Question

Problem with configure nginx (I guess) to cooperate with domain and not show ip address.

Posted April 21, 2020 280 views
NginxDjango

Hello, I bought a domain from GoDaddy and successfully configured it. When I go to http://mysite.com (just an example), I see my site but domain name (mysite) is translated to ip address. I can’t force nginx (it is nginx, right?) to use and show domain name only and not show ip address. It is a django project.

nginx configuration (/etc/nginx/sites-available/mysite):

server {
    listen 80;
    server_name  mysite.com www.mysite.com XXX.XXX.IP.IP;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/tuliokkj/portfolio-test-project;
    }

    location /media/ {
        root /home/tuliokkj/portfolio-test-project;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/tuliokkj/portfolio-test-project/portfolio.$
    }
}

django settings:

###SOME UNIMPORTANT STUFF

SECRET_KEY = '###'

ALLOWED_HOSTS = ['mysite.com', 'www.mysite.com', 'XXX.XXX.IP.IP']

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': '###',
        'USER': '###',
        'PASSWORD': '###',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}

DEBUG = False

if I delete ip address from Allowed hosts and nginx server_name list, I will get something like that:
Image1

if I add ip address to server_name in nginx configuration file but still without addin it to local_settings, I will get:
Image2

I tried many solutions from nginx tutorials, digitalocean tutorials and nothing helped. I’ll share godaddy configuration also:
Image3

I haven’t found language change option so I translated it for you:
Image4

I don’t even know if it is problem with django settings (I highly doubt it), ngingx (probably) or godaddy (maybe). Tell me if you need some more information for answer.

edited by MattIPv4

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.

×
1 answer

On your nginx configuration try server_name .mysite.com only. Then, open another server block like this

server {
    listen 80;
    server_name [YOUR_IP_HERE];
    return 301 $scheme://mysite.com$request_uri;
}

just in case… this is actually never needed.

Submit an Answer