Question

nginx default shows on my custom domain name, but my DO IP shows the proper site

Hi everyone,

I’m a bit confused as to where exactly my problem lies. I have a custom domain name, which I have connected to the DO nameservers. I’m reasonably sure this is set up correctly since as the title states, when I go to that website, I get the “welcome to nginx” default page.

However, when I go to my DO droplet’s IP; http://192.241.148.5/, I can see my webapp correctly.

I suspect the problem lies with my nginx sites-available/philheijkoopsite file (that’s what I’ve called it), containing the following:

server {
    listen 80;
    server_name 192.241.148.5;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/phil/mysite;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/phil/mysite/philheijkoopsite.sock;
    }
}

Is the server_name not specific enough? I have checked and the .sock file has been created, gunicorn is running correctly. I’ve tried restarting nginx, none of that has changed my currently problem, anyone have any ideas?

update I have added a new rule to my sites-available/philheijkoopsite file:

server {
    listen 80;
    server_name .philheijkoop.com;

    return 302 $scheme://192.241.148.5;
}

Which now redirects my incoming traffic to my IP, and thus they at least get to the web app. However, this does the opposite of what I want. If I reverse the current set up in my file, ie have the url redirect to my IP, it will do that, but the IP still serves a 400 Bad Request error.

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

If you want to show a custom page instead of the web app main page, you should map the public ip address of your server to a static page like index.nginx-debian.html Here is the code to do that

server{
        listen 80;
        server_name $remote_addr;
        location / {
                index index.nginx-debian.html;
                alias /var/www/html/;
        }
}

In this way, all the requests that goes to the 80 port number will automatically redirect to nginx page. You can also implement an https redirect but that’s almost the same. You only have to create a certificate from a CA or a SelfSigned

I know its too late but I recently faced same issue because the documentation is bit confusing. The solution was to add server_name as www.yourdomain.com instead of yourdomain.com and then restart both nginx and gunicorn.

/etc/nginx/sites-available/realtyredefine

server {
    listen 80;
    server_name realtyredefine.com;
    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/vinay/realtyredefine;
    }

    location /media/ {
        root /home/vinay/realtyredefine;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
}

In my site-available, I put my domain in server_name and added my domain in ALLOWED_HOST in setting.py .

Now When I go either to the domain or to IP both shows “Welcome to Nginx”

Did you resolve the problem? I have the same one.

This comment has been deleted

I’ve tried that; when it shows

...
 server_name philheijkoop.com;
...

I get a Bad Request (400) error when I go to that URL, and my droplet’s IP then shows the nginx default welcome page.

So the reason it’s set to my droplet’s IP is that’s something I tried that worked.

Hi there,

As long as you see the Welcome to Nginx page, your domain is pointing to the correct server. Now, we need to make it point to the correct page.

The first thing I noticed is the server_name directive. Do you have special reason why is it set to the Droplet’s IP address? Try to replace IP with your domain name such as:

...
   server_name example.com
...

Restart Nginx by running the systemctl restart nginx and then give it a try. Maybe, you’ll have to clear browser cache, or to use the incognito mode.

The rule you added later isn’t needed, it should work out-of-box. For more info how to set up this, I recommend you to look at the How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu 16.04 tutorial. If nothing helps, you can take a look at the How To Troubleshoot Common Site Issues on a Linux Server tutorial.