[Supplement] About uwsgi_params:
This is what the official website says:
Configure nginx for your site
You will need the uwsgi_params file, which is available in the nginx directory of the uWSGI distribution, or from https://github.com/nginx/nginx/blob/master/conf/uwsgi_params
Copy it into your project directory. In a moment we will tell nginx to refer to it.
[original]
When deploying uwsgi+nginx+django according to this document http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html, the combination of uwsgi and django or pure python can produce correct results. Install nginx
You can also see Welcome to nginx!
after refreshing the browser.
Then I created the nginx configuration file under the django project folder:
# mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
# server unix:///path/to/your/mysite/mysite.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 192.168.33.10; # 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/vagrant/mysite/mysite/media; # your Django project's media files - amend as required
}
location /static {
alias /home/vagrant/mysite/mysite/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/vagrant/mysite/mysite/uwsgi_params; # the uwsgi_params file you installed
}
}
But whether you try to directly use test.py to output hello world, or start the django server, you can still only see Welcome to nginx!
, with the path after the server ip. This is the only one.
When using test.py directly, the output is as follows:
$ uwsgi --socket :8001 --wsgi-file test.py *** Starting uWSGI 2.0.9 (64bit) on [Mon Feb 2 15:54:01 2015] ***
compiled with version: 4.6.3 on 02 February 2015 09:51:05
os: Linux-3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012
nodename: precise64
machine: x86_64
clock source: unix
detected number of CPU cores: 2
current working directory: /home/vagrant/mysite/mysite
detected binary path: /home/vagrant/mysite/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 2782
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.3 (default, Dec 18 2014, 19:25:50) [GCC 4.6.3]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1579b10
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 0x1579b10 pid: 1655 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 1655, cores: 1)
習慣沉默2017-05-16 17:27:22
Problem solved. In fact, it is because /etc/nginx/sites-enabled/
下面有两个配置文件:default
和我自己配置的mysite_nginx.conf
, nginx uses default by default. Just delete default.
高洛峰2017-05-16 17:27:22
The configuration file does not work. Check whether the nginx configuration file has been read correctly. First use the simplest demo to test whether the configuration file takes effect
高洛峰2017-05-16 17:27:22
Nginx is configured with port 8000, you need to access the 8000 port of nginx,
Your nginx django configuration is
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
So starting django should be based on port 8001.
uwsgi_params is in nginx. Configuration path error. uwsgi_params is in /etc/nginx/uwsgi_params
.
phpcn_u15822017-05-16 17:27:22
There is an interface conflict. First, each service only listens to 1 interface. According to the understanding of the configuration file, it should be, nginx:8000 django:8001
In this case, no error is reported when executing python manage.py runserver localhost:8000, indicating that the nginx configuration file does not work. It may be started using the default port 80. Please check the interface list. The linux command is:
netstat -natp | grep nginx
If you want to use a custom configuration file to start, please nginx -h to view the specific command, probably -p or -c.
When nginx is correctly configured to start, django should also be started using python manage.py runserver localhost:8001 to ensure it is consistent with the configuration file design
高洛峰2017-05-16 17:27:22
Did you bring the port number when you visited? http://192.168.33.10:8000
巴扎黑2017-05-16 17:27:22
Confirm whether the configuration file is pointed correctly, for example
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
PHP中文网2017-05-16 17:27:22
First, remember to bring the port number.
Secondly, the error message indicates that your configuration is wrong. Take a look at the error log.