0

I'm using django, uwsgi and nginx. I have tried nginx and django documentation for serving static files. My conf file is:

http {


upstream django {
    server 127.0.0.1:8000;
}

server {
    listen 80;
    server_name 192.xx.xx.x;

    root /path/to/project/;


    location /static/  {
        alias /path/to/static/;
    }

    location / {
        include /etc/nginx/uwsgi_params;
        uwsgi_pass django;

        uwsgi_param Host $host;
        uwsgi_param X-Real-IP $remote_addr;
        uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
        uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto;
    }
}
}

Is my config file true? Can I use IP Address in server_name section? (IP Address is my machine IP)

Jasmine
  • 243
  • 1
  • 3
  • 9
  • 1
    I recommend setting up a `/etc/hosts/` entry where you map domain name to your internal DNS name. This way you can use domain name locally, and avoid possible issues with using IP address only. – Tero Kilkanen Mar 13 '17 at 19:12

2 Answers2

1

Per https://nginx.org/en/docs/http/ngx_http_core_module.html#server:

There is no clear separation between IP-based (based on the IP address) and name-based (based on the “Host” request header field) virtual servers. Instead, the listen directives describe all addresses and ports that should accept connections for the server, and the server_name directive lists all server names.

An overview of how nginx processes requests can be found at https://nginx.org/en/docs/http/request_processing.html, and an overview of serving static content can be found here: https://www.nginx.com/resources/admin-guide/serving-static-content/.

There is nothing I can see in your config that would prevent things from working - did you test your config and run into any issues?

iwaseatenbyagrue
  • 3,688
  • 15
  • 24
1

Yes you can change servername as machine IP address to serve django application, the extra effort is, you have to assign host variable as IP address in settings.py file of your application.