I am trying to setup a 301 permanent redirect on my Ubuntu 18.04, Ghost 3.0 DigitalOcean Site.
I found some posts that mentioned i can do this with nginx by adding a few lines to the nginx.conf file.
I tried modifying etc/nginx/nginx.conf with the following server settings:
server {
. . .
server_name domain.com www.domain.com;
rewrite ^/ads.txt$ https://partner.com/ads.txt permanent;
. . .
}
But when i run nginx -t it says “server” directive not allowed. I suspect its related to the ghost installation. Based on what I read here, it seems I may need to be modifying different nginx.conf file/s. But which ones? And where?
In /var/www/ghost/system there is an nginx-root folder, but its empty. I tried adding the modified nginx.conf file there, but it does not seem to effect anything. I’m just guessing here now. Any help?
How do i setup a simple permanent 301 redirect? I could not find any step-by-step guide, only bits and pieces and i tried to puzzle them together but it didnt work.
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.
This command should restart the service:
sudo service nginx restart
You can then check
ps
output to see when the current nginx process was started:ps -eo pid,start_time,cmd | grep nginx
Compare that to the server’s time:
date
If that’s still not working as expected, you could try checking the nginx error log for any clues:
sudo tail -F /var/log/nginx/access.log
Re: the config file icons, I wouldn’t worry about that - if the conf file was corrupted or otherwise a problem, we’d see some errors with
nginx -t
or when restarting.Hope this helps and let us know if you have any more questions
Hi @mlolm,
First you need to find the proper configuration file. Go to your Nginx folder
/etc/nginx/
. In there you should see another foldersites-available
Go inside that folder and lists it’s contents :You should see a couple of files. Usually, your domain has a configuration there the same name as your domain. However, if you created this droplet from the MarketPlace it might be a little different. What you can try to do si :
Of course, remember to change domain.com with your actual domain. Anyway, the above command should show you the file that has your domain inside of it. You should edit that file.
As for the redirect, can you give a little bit more information on what exactly you want that redirect to be? I’ll need it so that I can provide you with the information you need to put in your Nginx configuration file.
Regards, KFSys