How to configure an NGINX & UWSGI in Django - django

I am deploying my Django app on VPS and I would like to use NGINX & UWSGI
I have followed this tutorial https://www.youtube.com/watch?v=ZpR1W-NWnp4 in order to configure my NGINX server.
Below is my NGINX configuration file named my_nginx.conf:
# the upstream component nginx needs to connect to
upstream django {
server unix:///root/PIDC/ProjetAgricole/uwsgi_nginx.sock; # for a file socket
# server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name 173.249.8.237; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /root/PIDC/ProjetAgricole/media; # your Django project's media files - amend as required
}
location /static {
alias /root/PIDC/ProjetAgricole/staticfiles; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /root/PIDC/ProjetAgricole/uwsgi_params; # the uwsgi_params file you installed
}
}
I just changed the paths only in this file.
When I run this command, I am getting this output that seems to be fine.
(venv) root#vmi851374:~/PIDC/ProjetAgricole# uwsgi --socket ProjetAgricole.sock --module ProjetAgricole.wsgi --chmod-socket=666
*** Starting uWSGI 2.0.20 (64bit) on [Fri Apr 22 22:36:02 2022] ***
compiled with version: 9.4.0 on 17 April 2022 18:54:03
os: Linux-5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022
nodename: vmi851374.contaboserver.net
machine: x86_64
clock source: unix
detected number of CPU cores: 4
current working directory: /root/PIDC/ProjetAgricole
detected binary path: /root/my_project/venv/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 31601
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address ProjetAgricole.sock fd 3
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Python version: 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x561dba821d90
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72904 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x561dba821d90 pid: 294717 (default app)
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 294717, cores: 1)
However, when I run the application in my browser, I ma getting the 502 Bad Gateway.
The content of the uwsgi_params file is:
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_ADDR $server_addr;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
I am getting confused about this error.
Please assist me.

Related

Why I am getting the NGINX welcome page instead of my Django application

I have deployed my Django Application on a VPS server. I have configured NGINX and uWSGI server.
Here is my Nginx configuration
# the upstream component nginx needs to connect to
upstream django {
server unix:///root/PIDC/ProjetAgricole/ProjetAgricole.sock; # for a file socket
# server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 8000;
# the domain name it will serve for
server_name my_public_IP_address; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /root/PIDC/ProjetAgricole/media;
}
location /static {
alias /root/PIDC/ProjetAgricole/static;
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /root/PIDC/ProjetAgricole/uwsgi_params;
}
}
Here is my mysite_uwsgi.ini file
# mysite_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /root/PIDC/ProjetAgricole
# Django's wsgi file
module = project.wsgi
# the virtualenv (full path)
home = /root/my_project/venv
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = /root/PIDC/ProjetAgricole/ProjetAgricole.sock
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
When I am running the Django application with uwsgi and nginx by using this command:
uwsgi --socket ProjetAgricole.sock --module ProjetAgricole/ProjetAgricole.wsgi --chmod-socket=664
I am getting this output as a result of the command:
(venv) root#vmi851374:~/PIDC/ProjetAgricole# uwsgi --socket ProjetAgricole.sock --module ProjetAgricole/ProjetAgricole.wsgi --chmod-socket=664
*** Starting uWSGI 2.0.20 (64bit) on [Sun Apr 24 18:57:17 2022] ***
compiled with version: 9.4.0 on 17 April 2022 18:54:03
os: Linux-5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022
nodename: vmi851374.contaboserver.net
machine: x86_64
clock source: unix
detected number of CPU cores: 4
current working directory: /root/PIDC/ProjetAgricole
detected binary path: /root/my_project/venv/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 31601
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address ProjetAgricole.sock fd 3
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Python version: 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x55d5d758ada0
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72904 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
ModuleNotFoundError: No module named 'ProjetAgricole/ProjetAgricole'
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 327968, cores: 1)
The content of /root/PIDC/ProjetAgricole/uwsgi_params is:
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_ADDR $server_addr;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
When I run my application via the web browser it is displaying the NGINX welcome page instead of my project home page which is supposed to appear.
Are there any mistakes in the configurations files?
Please assist

uwsgi & Django with port 80

If I run uwsgi with uwsgi --ini kb_uwsgi.ini --http :80 it gives me an error:
[uWSGI] getting INI configuration from kb_uwsgi.ini
*** Starting uWSGI 2.0.14 (64bit) on [Thu Jan 26 12:34:51 2017] ***
compiled with version: 5.4.0 20160609 on 06 January 2017 11:55:37
os: Linux-4.4.0-53-generic #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016
nodename: ip-172-31-16-133
machine: x86_64
clock source: unix
detected number of CPU cores: 4
current working directory: /home/ubuntu/webapps/kenyabuzz
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /home/ubuntu/webapps/kenyabuzz
your processes number limit is 64137
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
bind(): Permission denied [core/socket.c line 769]
the site loads however if i preceed the command with sudo or use port :8000 eg uwsgi --ini kb_uwsgi.ini --http :8000
Now I tried to make the site live with nginx and uwsgi I get a 502 Bad Gateway nginx/1.10.0 (Ubuntu) nginx works okay because the favicon loads and I can access static files with \static\... I know this is Django having an issue rendering. I've tried also loading uwsgi --ini kb_uwsgi.ini --http :8000 without loading the djangoenv and it still loads.
The kb_uwsgi.ini file looks like this:
# kb_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /home/ubuntu/webapps/kenyabuzz
# Django's wsgi file
module = kb.wsgi
# the virtualenv (full path)
home = /home/ubuntu/webapps/djangoenv
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = /tmp/kb.sock
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
and the kb_nginx.conf like so
# kb.conf
# the upstream component nginx needs to connect to
upstream django {
server unix:///tmp/kb.sock; # for a file socket
#server 0.0.0.0:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name kenyabuzz.nation.news; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /home/ubuntu/webapps/kenyabuzz/kb/media; # your Django project's media files - amend as required
}
location /static {
alias /home/ubuntu/webapps/kenyabuzz/kb/static; # your Django project's static files - amend as required
}
location /favicon.ico {
alias /home/ubuntu/webapps/kenyabuzz/kb/static/kb/favicon.ico; # favicon
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /home/ubuntu/webapps/kenyabuzz/uwsgi_params; # the uwsgi_params file you installed
}
}
The log has:
2017/01/26 13:02:17 [crit] 4065#4065: *10 connect() to unix:///tmp/kb.sock failed (2: No such file or directory) while connecting to upstream, client: 197.232.12.165, server: kenyabuzz.nation.news, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///tmp/kb.sock:", host: "kenyabuzz.nation.news"
uwsgi should create the file automatically (it does) and it deletes it when it's closed using the example above.
Appreciate any help on this.
UPDATE
edited the .ini file and uncommented out the chmod-socket=664 the kb.sock file is still not created on restarting nginx.
For nginx:
# kb.conf
...
# the upstream component nginx needs to connect to
upstream django {
server unix:/tmp/kb.sock;
}
...
For uWSGI:
# kb_uwsgi.ini file
[uwsgi]
...
# the socket (use the full path to be safe
socket = /tmp/kb.sock
chmod-socket = 666
...

deploying django app on nginx with uwsgi returns a 502 - permission denied

I'm trying to setup a simple django app on nginx with uswgi.
When I send a request, it returns a 502 bad gateway.
Here is my uwsgi.ini
[uwsgi]
master = true
socket = /usr/share/nginx/firstsite/nginx.sock
chdir = /usr/share/nginx/firstsite
wsgi-file = /usr/share/nginx/firstsite/firstsite/wsgi.py
chmod-socket = 664
vacuum = true
uwsgi output:
uwsgi --ini uwsgi.ini
[uWSGI] getting INI configuration from uwsgi.ini
*** Starting uWSGI 2.0.11.2 (64bit) on [Sat Jun 18 15:09:30 2016] ***
compiled with version: 4.8.3 20140911 (Red Hat 4.8.3-9) on 02 December 2015 19:47:02
os: Linux-3.10.0-327.4.4.el7.x86_64 #1 SMP Tue Jan 5 16:07:00 UTC 2016
nodename: centos_prod
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 8
current working directory: /usr/share/nginx/firstsite
detected binary path: /root/venv/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
chdir() to /usr/share/nginx/firstsite
your processes number limit is 94006
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /usr/share/nginx/firstsite/nginx.sock fd 3
Python version: 2.7.5 (default, Nov 20 2015, 02:00:19) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x21f6ce0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145536 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x21f6ce0 pid: 3421 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 3421)
spawned uWSGI worker 1 (pid: 3426, cores: 1)
nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
upstream django {
server unix:///usr/share/nginx/firstsite/nginx.sock;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/firstsite;
client_max_body_size 300M; # adjust to taste
location /media {
alias /usr/share/nginx/firstsite/media;
}
location /static {
alias /usr/share/nginx/firstsite/static;
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /usr/share/nginx/firstsite/uwsgi_params; # the uwsgi_params file you installed
}
}
}
I'm not using a virtualenv and my manage.py is in /usr/share/nginx/firstsite/
I'm able to run the app without nginx on uwsgi with:
uwsgi --wsgi-file /usr/share/nginx/firstsite/firstsite/wsgi.py --http :80
but what I'm trying to do is let nginx use port 80 and uwsgi use file socket.
Please help.
Update:
I don't know why I was not seeing any error before, but now nginx error log says:
nginx Permission denied while connecting to upstream
so looking at this
I tried adding these options to uwsgi:
--uid root --gid www-data
so the socket file is owned by root which is part of the www-data group.
I'm still getting a permission error.
[crit] 6804#0: *1 connect() to unix:///usr/share/nginx/firstsite/nginx.sock failed (13: Permission denied) while connecting to upstream, client: 192.168.168.201, server: _, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///usr/share/nginx/firstsite/nginx.sock:"
Update:
I'm still running into permission issue.
I created a django user and a django group.
Both nginx and django users are members of django group.
Changed ownership of all the folders under
/usr/share/nginx/firstsite
owned by django.
set --gid and --uid to django.
ran
uwsgi --ini /usr/share/nginx/firstsite/uwsgi.ini
as root. I got the permission error.
ran:
runuser -l django -c "uwsgi --ini /usr/share/nginx/firstsite/uwsgi.ini"
the same.
Note that /usr/share/nginx is owned by root.
I tried changing the nginx config file:
uwsgi_pass unix:///usr/share/nginx/firstsite/nginx.sock;
restarted nginx and ran uwsgi. I'm getting this error:
connect() to unix:///usr/share/nginx/firstsite/nginx.sock failed (13: Permission denied) while connecting to upstream, client: 192.123.123.123, server: _, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///usr/share/nginx/firstsite/nginx.sock:"
I also had to setup a python virtualenv and set home in uwsgi.ini to detect django but I cannot get passed this socket failure.

django nginx uwsgi ubuntu server deploying fail

I am trying to set up my little Django project (Django 1.8) with nginx and uwsgi, but it just fails when running:
uwsgi --socket :8001 --wsgi-file test.py
which follows documentation.
I do not know why? I just step by step but when I run above command and check my serverip:8000 it shows nothing. However when I run:
uwsgi --http :8000 --wsgi-file test.py
it works and shows Hello World web site. Running command:
uwsgi --http :8000 --module myproject.wsgi
it works and shows myproject web site.
But when it comes to
uwsgi --socket :8001 --wsgi-file test.py
it just fails..
here is my nginx site config:
upstream django {
#server unix:///home/ubuntu/path/myproject/myproject.sock; # for a file socket
server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 8000;
# the domain name it will serve for
server_name 123.123.123.123; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /home/ubuntu/path/myproject/media; # your Django project's media files - amend as required
}
location /static {
alias /home/ubuntu/path/myproject/myapp/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /home/ubuntu/path/myproject/uwsgi_params; # the uwsgi_params file you installed
}
}
the uwsgi_params
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param REQUEST_SCHEME $scheme;
uwsgi_param HTTPS $https if_not_empty;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
Log from (not working) uWSGI command:
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7862
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address :8001 fd 3
Python version: 2.7.6 (default, Jun 22 2015, 18:01:27) [GCC 4.8.2]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1ad5ec0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72768 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x1ad5ec0 pid: 13959 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 13959, cores: 1)

Why is nginx returning a 502 when doing a `uwsgi_pass` to a linked docker container?

I'm using Docker Compose to orchestrate a multi-container app composed of both a Django webapp and an nginx reverse-proxy.
I'm staring with a simple test-case, but I've already hit a roadblock. The app should pass all requests to / over to the Django application by way of uwsgi_pass over a network socket (frontend:8000).
However, after starting the application with docker-compose up and seeing no error message, any request to / produces the following error message in the console: gateway_1 | 2016/01/11 15:45:12 [error] 8#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.99.1, server: localhost, request: "GET / HTTP/1.1", upstream: "uwsgi://172.17.0.2:8000", host: "192.168.99.100:8000"
My question is as follows: What might the problem be? Replacing uwsgi_pass frontend; in the location block with content_by_lua_file path/to/file.lua; behaves as expected, so I suspect a problem with uWSGI over a container link, but I'm at a loss for where to look next.
Below are the relevant files:
Docker Compose: the 30,000-ft view
The docker-compose.yml file is as follows:
postgres:
image: mystuff/app.testdb:latest
expose:
- "5432"
frontend:
image: mystuff/app.frontend:latest
expose:
- "8000"
environment:
APP_DBCONN: "user=xxx dbname=xxx port=5432 host=postgres sslmode=require password=xxx"
APP_ENV: "test"
gateway:
image: mystuff/app.gateway:latest
links:
- frontend
expose:
- "8000"
ports:
- "8000:8000"
NGINX: the reverse proxy
Below is my nginx.conf file:
worker_processes 1;
user me;
events {
use epoll;
worker_connections 1024;
}
http {
access_log /dev/stdout;
upstream frontend {
server frontend:8000; # assumption: `frontend` is a known hostname thanks to docker-compose
}
server {
listen 8000;
server_name localhost;
location / {
uwsgi_pass frontend;
include uwsgi_params;
}
}
}
And lastly, here is my uwsgi_params file:
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param REQUEST_SCHEME $scheme;
uwsgi_param HTTPS $https if_not_empty;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
uWSGI & Django: the application server
uwsgi.ini:
[uwsgi]
chdir = /home/app
wsgi-file = ./NFC/wsgi.py
socket = 127.0.0.1:8000
master = true
processes = 1
threads = 2
uid = me
Edits
1. Log output with http = 127.0.0.1:8000 in uwsgi.ini
$ cat /tmp/uwsgi.log
*** Starting uWSGI 2.0.12 (64bit) on [Wed Jan 13 12:09:44 2016] ***
compiled with version: 4.9.2 on 03 January 2016 21:09:04
os: Linux-4.1.13-boot2docker #1 SMP Fri Nov 20 19:05:50 UTC 2015
nodename: default
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /home/srg
detected binary path: /home/srg/.pyenv/versions/2.7.11/bin/uwsgi
chdir() to /home/srg
your processes number limit is 1048576
your memory page size is 4096 bytes
detected max file descriptor number: 1048576
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on 127.0.0.1:8000 fd 7
uwsgi socket 0 bound to TCP address 127.0.0.1:38922 (port auto-assigned) fd 6
Python version: 2.7.11 (default, Jan 3 2016, 21:07:12) [GCC 4.9.2]
Python main interpreter initialized at 0x1d37300
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 166144 bytes (162 KB) for 2 cores
*** Operational MODE: threaded ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x1d37300 pid: 173 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 173)
spawned uWSGI worker 1 (pid: 210, cores: 2)
spawned uWSGI http 1 (pid: 211)
SIGINT/SIGQUIT received...killing workers...
gateway "uWSGI http 1" has been buried (pid: 211)
worker 1 buried after 1 seconds
goodbye to uWSGI.
With that uWSGI configuration, especially with:
socket = 127.0.0.1:8000
uWSGI will allow only local connection (which means from same docker, not from host or other dockers). To allow connections from outside of docker, you must change it to:
socket = :8000
Try adding the following property to your .ini config.
chmod-socket = 666