问题描述:
Nginx+Gunicorn部署 Django后遇到Not Found错误
服务器版本:CentOS 7.5 x64
说明:在虚拟环境中使用django自带的runserver运行(0.0.0.0:8000)后,使用公网IP:端口/index可以正常访问项目,关闭debug后使用
pipenv run gunicorn blogproject.wsgi -w 2 -k gthread -b 0.0.0.0:8000
运行也可以正常访问,但是开启nginx后运行就出现如图错误。
/etc/nginx/conf.d/django-blog.conf配置如下
[zijeak@VM_16_8_centos conf.d]$ cat django-blog.conf
server {
charset utf-8;
listen 80;
server_name 119.27.169.70;
location /static {
alias /home/zijeak/apps/django-blog/static;
}
location / {
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8000;
}
}
查看nginx日志如下:
[zijeak@VM_16_8_centos conf.d]$ sudo nginx -t
[sudo] password for zijeak:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
项目目录如下: