Anshul
Anshul

Reputation: 387

nginx not working with gunicorn for external IP's

I am using nginx and gunicorn for a django application on AWS. Here is my /etc/nginx/sites-enabled/mywebsite

server {
    listen 80;
    server_name mywebsite.com;
    location / {
        proxy_pass http://127.0.0.1:8001;
    }

    location /static/ {
        autoindex on;
        alias /home/ubuntu/mywebsite/staticfiles/;
    }
}

The Gunicorn command I am running.

gunicorn mywebsite.wsgi:application --bind=127.0.0.1:8001

All this is on AWS

The problem is I can access the website by going to mywebsite.com and it works as expected on any machine on my home network but other people(not on my home network) still get welcome to nginx.

I have the domain mywebsite.com pointed to my was elastic IP I also have port 80 open on AWS.

Upvotes: 2

Views: 1835

Answers (1)

Edwin Lunando
Edwin Lunando

Reputation: 2816

There are high posibility that the other person outside your network will access www.mywebsite.com. Change the server_name into.

server {
    listen 80;
    server_name mywebsite.com www.mywebsite.com;
    location / {
        proxy_pass http://127.0.0.1:8001;
    }

    location /static/ {
        autoindex on;
        alias /home/ubuntu/mywebsite/staticfiles/;
    }
}

Upvotes: 3

Related Questions