nginx+uwsgi部署django,8000端口正常,80端口404

发布于 2022-09-04 08:43:18 字数 2776 浏览 21 评论 0

按照教程用nginx+uwsgi部署django项目,监听8000端口正常,80端口访问时显示404 not found.
django项目目录为/home/wu/Documents/env/myblog
项目文件夹下文档结构
图片描述

myblog_nginx.conf文件

# 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文件

# 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文件中改为8000端口时没问题
图片描述

改为80端口后,raload,restart nginx,uwsgi --ini mysite_uwsgi.ini,然后访问
图片描述

端口状态:
图片描述

求指点,搞了好久都没解决这个问题,感激不尽!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

才能让你更想念 2022-09-11 08:43:18

请问你的问题解决了吗?

偏闹i 2022-09-11 08:43:18

请问兄台如何部署,,写个教程吧。。

策马西风 2022-09-11 08:43:18

8000 端口显示的那个页面是 Django 自带的测试页,在 80 端口部署的时候应该不会出现,建议你自己写个页面部署到 80 端口试试

烈酒灼喉 2022-09-11 08:43:18

是不是你其他地方配置了

server {
    listen      80;
    xxx
}
#导致没进入你的server块,看下nginx.conf,或者其他虚拟主机的配置文件。

另外你的
server {
    /*这个去掉吧,或者你可以测试重复,host配置一个xxx.com,
    这边也配置为xxx.com,相比于listen 80,会优先进入这个server块。*/
    #server_name .example.com;
}
此生挚爱伱 2022-09-11 08:43:18

nginx里面的location配置,include uwsgi_params;后面你没有uwsgi_pass 127.0.0.1:8000;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文