Use nginx+uwsgi to deploy the django project according to the tutorial. Listening to port 8000 is normal. When accessing port 80, 404 not found is displayed.
The django project directory is /home/wu/Documents/env/myblog
Document structure under the project folder
myblog_nginx.conf
File
# mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
server unix:///home/wu/Documents/env/myblog/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 80;
# the domain name it will serve for
server_name .example.com; # 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/wu/Documents/env/myblog/media; # your Django project's media files - amend as required
}
location /static {
alias /home/wu/Documents/env/myblog/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
root /home/wu/Documents/env/myblog;
uwsgi_pass django;
include /home/wu/Documents/env/myblog/uwsgi_params; # the uwsgi_params file you installed
}
}
mysite_uwsgi.ini
File
# mysite_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /home/wu/Documents/env/myblog
# Django's wsgi file
module = myblog.wsgi
# the virtualenv (full path)
home = /home/wu/Documents/env
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = /home/wu/Documents/env/myblog/mysite.sock
# ... with appropriate permissions - may be needed
chmod-socket = 666
# clear environment on exit
vacuum = true
myblog_nginx.conf
There is no problem when the file is changed to port 8000
After changing to port 80, raload, restart nginx, uwsgi --ini mysite_uwsgi.ini
, and then visit
Port status:
Please give me some advice, I haven’t solved this problem for a long time, I would be very grateful! ! !
仅有的幸福2017-05-16 17:13:06
The page displayed on port 8000 is the test page that comes with Django. It should not appear when deployed on port 80. It is recommended that you write a page yourself and deploy it to port 80 to try it
PHPz2017-05-16 17:13:06
Did you configure it elsewhere
server {
listen 80;
xxx
}
#导致没进入你的server块,看下nginx.conf,或者其他虚拟主机的配置文件。
另外你的
server {
/*这个去掉吧,或者你可以测试重复,host配置一个xxx.com,
这边也配置为xxx.com,相比于listen 80,会优先进入这个server块。*/
#server_name .example.com;
}
天蓬老师2017-05-16 17:13:06
The location configuration in nginx includes uwsgi_params; you don’t have uwsgi_pass 127.0.0.1:8000;