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.


Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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”