Reputation: 305
I wanted to use custom domain for Github Pages, with HTTPS enabled using my own certs(not a CloudFlare one).
According to Github Pages instruction, the first part is done by setting up a CNAME both in project root folder and DNS, but this way HTTPS is not supported: https://example.github.io
with custom domain example.com
is only accessible in http://example.com
, https://example.com
won't work.
Thus I'm thinking of nginx reverse proxy: remove CNAME file and DNS setting, let 3 links co-exist, redirect http custom domain to https one, forward requests of https one to github.io
address.
However, result is not perfect: homepage and css(in /css/main.css !) are loaded correctly, all links are displayed normally, but click them will result in 301 and redirected to github.io.
My nginx version is 1.9.5, configuration for port 80:
server {
listen 80;
server_name myblog.com;
return 301 https://$server_name$request_uri;
}
for 443:
server {
listen 443 ssl http2;
server_name myblog.com;
ssl_certificate /etc/nginx/ssl/orz.crt;
ssl_certificate_key /etc/nginx/ssl/orz.key;
add_header Strict-Transport-Security max-age=31536000;
location / {
proxy_pass https://example.github.io;
proxy_set_header Host example.github.io;
}
}
Upvotes: 2
Views: 3738
Reputation: 305
fixed by adding 2 lines:
proxy_redirect https://example.github.io https://example.com;
proxy_redirect http://example.github.io https://example.com;
And btw, if you want to host Jekyll/Ghost on Github Pages, make sure your posts' permalink end in /
, or it will cost another 301..
Add server side push for css file if using Jekyll, on server
block:
add_header Link '</css/main.css>; rel=preload; as=stylesheet';
Upvotes: 1