[Answer]-With DEBUG=False django in EC2 in AWS, domain, stage.example.com is not reachable

0๐Ÿ‘

โœ…

I got this worked out later time. The issue was due to PREPEND_WWW django setting. With this option on, DNS was not resolved because it keeps going to www.stage.xxx.xxx first before it is resolved by DNS.

๐Ÿ‘คImju

1๐Ÿ‘

If nginx / gunicorn generally you can run on 127.0.0.1 since nginx is a reverse proxy.

# settings.py
ALLOWED_HOSTS = ['127.0.0.1']

Nginx conf in sites-available / sites-enabled

server {
    server_name example.com;

    access_log off;

    location /static/ {
        alias /var/www/django-path-to-static-root;
    }

    location / {
            proxy_pass http://127.0.0.1:8001;
            proxy_set_header X-Forwarded-Host $server_name;
            proxy_set_header X-Real-IP $remote_addr;
            add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
    }
}

gunicorn

gunicorn something.wsgi --bind 127.0.0.1:8001
๐Ÿ‘คMikeec3

Leave a comment