Question

Nginx "welcome to Nginx" only on Moblie Devices

Posted April 15, 2019 502 views
NginxDigitalOceanDjangoUbuntu 16.04

I made a website for a friend for his carpet cleaning business. I followed https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04 exactly. I also have my own website set up and it works perfectly. But for the carpet cleaning business when I am on the computer I get the website as it is suppose to be but when I go to my phone or any other phone that has never accessed the site I get the “welcome to nginx” page. I doubled checked ALL settings with my website and his and the only difference is the names of things, such as domains and other files. I used Django as my frame work and am hosting it on ubuntu 16.04 server on digital ocean. The carpet cleaning website is : chiltoncarpetcleaning.com.

I did move the sock file but this works fine for my site and I doubt that would make this error

/etc/systemd/system/gunicorn.service:

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=username
Group=www-data
WorkingDirectory=/home/username/app
ExecStart=/home/username/app/env/bin/gunicorn –workers 3 –bind unix:/home/username/app.sock app.wsgi:application

[Install]
WantedBy=multi-user.target

/etc/nginx/sites-available/app

server {
listen 80 defaultserver;
server
name chiltoncarpetcleaning.com www.chiltoncarpetcleaning.com;

root /home/username/app;

location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
    root /home/username/app;
}
location /media/ {
    root /home/username/app;
}

location / {
    include proxy_params;
    proxy_pass http://unix:/home/username/app.sock;
}

}

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.

×
2 answers

Greetings!

It sounds like the hostname being called is capturing the default Nginx server block, which is serving the HTML contents of /var/www/html or similar. While it can be confusing to see, luckily this really narrows the scope of the problem significantly. It may require careful reviewing of what has been done thus far, making no assumptions that something was not overlooked. It’s really going to come down to these two:

  1. There is no other server block in your Nginx configuration which is set to interpret requests from that hostname. This is the server_name variable in your Nginx server blocks. If the domain/hostname being called in the URL bar does not match one of your server_name values, it should go to the default Nginx page (different if you’ve disabled this, but then you still wouldn’t be seeing that page, so safe to say it isn’t disabled).

  2. DNS is pointing somewhere else that you weren’t expecting it to. Maybe you’re loading the page from an entirely different server, perhaps intermittently and perhaps not. Maybe you left two A records for the domain so that visits randomly hit one of two IP addresses, and your mobile device cached the other IP on a lookup. Maybe you edited your host file on your local computer and never actually updated the DNS for the domain, so when you use a device other than your computer you load the site from a different server.

It’s hard to say what the actual problem is, but it really should come down to just those two. Not matching a server block or not loading from the server you’re expecting it to.

Jarland

Ok so I don’t know why but I added certbot and ssl and now it works on moblie. I did nothing but follow https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04

by Mitchell Anicas
In this tutorial, we will show you how to use Let's Encrypt to obtain a free SSL certificate and use it with Nginx on Ubuntu 16.04. We will also show you how to automatically renew your SSL certificate. If you're running a different web server, simply follow your web server's documentation to learn how to use the certificate with your setup.
Submit an Answer