IP Address Forward


So I have been using EasyEngine for a few WordPress websites and it is great. I am a rookie though when it comes to Nginx. I have searched around but have not found anything that solves my issue. A lot of resources are building a Nginx setup from scratch and the forum here I was not able to find a answer. So here it goes:

So my website is up and running and everything works great but when I visit the IP address I get the “Welcome to Nginx” screen. I wish to have the ip address direct to the domain name and show the website. It is on Digital Ocean and it is a single website on the droplet so I just wish for it to direct to the domain name. I have tried to add a server block in the /etc/nginx/nginx.conf file as well as to the /etc/nginx/sites-available/mydomain.com file. I have tried various solutions I have found and I always get an error.

Here are some errors I have received: Reload : nginx [Failed] service nginx reload failed. check issues with nginx -t command

Job for nginx.service failed because the control process exited with error code. See “systemctl status nginx.service” and “journalctl -xe” for details.

If anyone can help this rookie out, I will highly appreciate it!

Thank you

Whats the output of “systemctl status nginx.service” and “journalctl -xe” ?

vim /etc/nginx/sites-available/default

Locate a block with location / { ... }, comment everything in it and place in it:

return 301 $scheme://domain.com$request_uri;

Then test the configuration and if no errors reload Nginx:

nginx -t && service nginx reload

This probably will solve your problem.

You are welcome. :slight_smile:

1 Like

Actually, what matters here is the output of nginx -t.

@portofacil, brilliant!

@ggloveswp, I was getting ready to reply to you but what @portofacil recommended worked.

I don’t mean to take up any more of your time then you have already invested in helping me, @portofacil, but can you briefly explain to me why that worked but me doing the below in /etc/nginx/sites-available/mydomain.com and /etc/nginx/nginx.conf didn’t work?

server { listen 443; server_name xxx.xxx.xx.xxx; return 301 https://www.mydomain.com$request_uri; }

I guess the main question is, what are the key differences between these three files?

/etc/nginx/sites-available/mydomain.com /etc/nginx/nginx.conf /etc/nginx/sites-available/default

Thank you

sites-available/mydomain.com = your domain specific rules; it is what old school guys like me call a “vhost file”

nginx.conf = the default configuration of Nginx, out of any vhost file

sites-available/default = the vhost file for the “default” website, i.e., any domain name that resolves to the server but has no specific vhost file

That’s why you had to to put your custom redirect in /etc/nginx/sites-available/default, because this is the vhost file for the default site with no custom vhost. :slight_smile:

I think I was not that clear, so please don’t worry about asking again.

1 Like

I appreciate your help. That helps me. I always like to learn rather than copy and paste so I appreciate your time to explain.