Using HTTPS with Github Pages and a Custom Domain

Github pages is a very convenient way to host both personal websites, and project websites. Websites are linked to a git branch or repo, and update when pushed too. Github pages supports custom domains as well! Whilst Github Pages supports HTTPS for websites, it does not support HTTPS when using a custom domain.

However, we can use a proxy server to allow us to use a custom domain with HTTPS! Both the connection between the client and the proxy server, and the proxy server and Github will be secure.

Whilst you lose the advantage of Github’s CDN, you still have the following advantages:

  • Websites are linked to a git repo, and you don’t have to worry about pulling changes and rebuilding the sites yourself.
  • Storage space is saved on the server.

Add CNAME file

This is recommended to make sure that is redirected to

Create an NGINX proxy

Point your DNS to the proxy server instead of

Add the following virtual server to your sites file:

server {
	listen 443 ssl http2;

	# Insert SSL specific settings here

	location / {
		proxy_intercept_errors on;

		# Makes us request, instead of
		proxy_set_header Host;
		proxy_set_header X_FORWARDED_PROTO https;

		# Give GitHub control over caching headers
		expires off;

# Redirect HTTP to HTTPS
server {
	listen 80;
	listen [::]:80;
	return 301 https://$server_name$request_uri;

Setting up NGINX and SSL is out of scope for this tutorial, I’m assuming you know how to configure both. If not, have a look at installing NGINX and securing NGINX with Let’s Encrypt.

Make sure you add the domain to your certificate first.

Be warned that if you have HSTS enabled, you won’t be able to go back to HTTP.


Comments are currently disabled whilst we remove the dependency on a third party service which was taken offline. In the meantime, feel free to send a message to me on Twitter.