I just added your code block (after tweaking a little bit) to /etc/nginx/default.conf
server {
server_name example.com www.example.com;
return 301 https://blog.example.com$request_uri;
}
Now the www.example.com is redirecting successfully to https://blog.example.com
but when I tried https://example.com It said that This site can’t be reached
I know that is happening because in my default.conf, It’s only listening for :80
And I think that listening for :443 won’t work because the https is configured for my subdomain only https://blog.example.com.
Do I have to add one more https certificate for my main domain https://example.com?
*I’m using LetsEcnrypt (It asked me during installation via ghost-cli).
Thank you for sharing this.
I’ll be marking this as solved. I almost got the results what I wanted (just 1 redirection is causing problem and I was going to figure It out unless I was hit with LetsEncrypt rate limit).
Anyways, If anyone wants to get the same results as me, I’ll suggest installing NGINX first then setting up a LetsEncrypt certificate on main domain.
Afterwards install Ghost on a subdomain.
Then redirect from main domain to subdomain.