Question

Setting up a 301 redirect with Nginx for my Ghost blog?

Posted April 15, 2018 23.7k views
NginxGhostUbuntu 16.04

Hi there,

I done the one click Ghost install and this works fine.

Then I decided to move my blog:
FROM: blog.club.in (ccTLD)
TO: blog.club.com (gTLD)

Basically from a ccTLD to a gTLD.

How do I setup a 301 with Nginx to redirect all http and https traffic from my ccTLD to the .com?

Thanks!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
4 answers
server {

  listen 80
  listen 443;

  server_name blog.club.in;

  location / {
    return 301 https://blog.club.com$request_uri;
  }

}

Hi Jason,

Thanks for your answer.
I have a follow up question.

Which is the file to modify? (is it default) or the conf file pertaining to ccTLD (club.in)

I have screenshots that might help:
1) This is etc/nginx/sites-available directory:
https://i.imgur.com/OUF2UIR.png

2) These are the conf files inside the ghost directory:
https://i.imgur.com/gnKMKup.png

Thanks!

  • as @aysadx states, you can it in the /etc/nginx/nginx.conf file. However I prefer to keep things neat and organized.

    Ensuring that the directory /etc/nginx/conf.d exists and this line exists in your http block in /etc/nginx/nginx.conf file:

    ...
    include /etc/nginx/conf.d/*.conf;
    ...
    

    You can create and enter the above configuration into its own file /etc/nginx/conf.d/club.in.conf

you can set the config from <jasonjpeters> directly to your nginx.conf innerline to section http {} like

“`http {

server {

listen 80
listen 443;

server_name blog.club.in;

location / {
return 301 https://blog.club.com$request_uri;
}

}


}


please know that "..." dots are your other config parameters
  • I managed to solve the issue.

    The line to be added is:

    return 301 https://blog.club.com$request_uri;
    

    Where does it need to go?
    If you’re using the one-click install of Ghost, then modify BOTH the .conf files (for http and https) in the /var/www/ghost/system directory

    Run

    nginx -t
    
    

    to check if the config was okay

    Restart nginx and then you should be good to go.

    The mistake I was making was trying to mirror my .conf files to the above examples. When I just added the 301 redirect leaving everything else as is, it worked.

    thanks jason, aysadx for your help! much appreciated.

Submit an Answer