Defining correctly Nginx server block for two django apps and no server_name -


i have been following digital ocean tutorial how serve django applications uwsgi , nginx on ubuntu 14.04, later can deploy own django application using nginx+uwsgi.

in tutorial create 2 basic django apps later served nginx. have tested apps working using django server , uwsgi alone.

when passed nignx part ran problem, dont have server_name have ip work with, , tried differentiate between django apps using port number.

the default nginx server (xxx.xxx.xxx.xxx:80) responding correctly, when try access django apps using (xxx.xxx.xxx.xxx:8080 or xxx.xxx.xxx.xxx:8081) 502 bad gateway.

i think have problem in way or logic defining listen inside server block. correct way of doing this, or might doing incorrectly.

this server blocks (in sites-enabled):

firstsite app

server {     listen xxx.xxx.xxx.xxx:8080;     #server_name _;      location = /favicon.ico { access_log off; log_not_found off; }     location /static/ {         root /root/firstsite;     }      location / {         include         uwsgi_params;         uwsgi_pass      unix:/root/firstsite/firstsite.sock;     } } 

econdsite app

server {     listen xxx.xxx.xxx.xxx:8081;     #server_name _;      location = /favicon.ico { access_log off; log_not_found off; }     location /static/ {         root /root/secondsite;    }      location / {         include         uwsgi_params;         uwsgi_pass      unix:/root/secondsite/secondsite.sock;    } } 

default nginx

server {     listen 80 default_server;     #listen [::]:80 default_server ipv6only=on;      root /usr/share/nginx/html;     index index.html index.htm;      # make site accessible http://localhost/     server_name localhost;      location / {             # first attempt serve request file,             # directory, fall displaying 404.             try_files $uri $uri/ =404;             # uncomment enable naxsi on location             # include /etc/nginx/naxsi.rules     } } 

update:

i checking error log under /var/log/nginx , when try connect firstsite following error:

2016/02/05 15:55:23 [crit] 11451#0: *6 connect() unix:/root/firstsite/firstsite.sock failed (13: permission denied) while connecting upstream, client: 188.37.180.101, server: , request: "get / http/1.1", upstream: "uwsgi://unix:/root/firstsite/firstsite.sock:", host: "178.62.229.183:8080"

nginx server on ubuntu run on www-data user default, uwsgi server won't (which thing, unless runs on root). if you're creating unix socket uwsgi, access defined system file. , default, access might restricted user created socket.

more on that, you're creating sockets in /root/ directory. directory readable root user , of linux distributions won't allow accessing inside if permissions set correctly.

so have is:

  1. put sockets outside of /root/ directory (/var/run place that)
  2. make sure nginx have access sockets (put --chmod-socket 666 or `--chown-socket yourusername:www-data uwsgi startup line)

and if you're running uwsgi server on root, aware dangerous. process running on root can system, if make mistake in code or hack in, can inject malicious software server, steal data or destroy everything.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -