python - django的uwsgi部署时,socket问题

 黑夜乱来 发布于 2022-10-31 14:35

文件:

blogtest_nginx.conf the upstream component nginx needs to connect to

upstream django {
# server unix:///home/aljun/djangotest/blogtest/blogtest.sock; # for a file socket
server 127.0.0.1:8000; # 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 .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/aljun/djangotest/blogtest/media;  # your Django project's media files - amend as required
}

location /static {
    alias /home/aljun/djangotest/blogtest/statices; # 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/aljun/djangotest/blogtest/uwsgi_params; # the uwsgi_params file you installed
}

}

当我执行:

uwsgi --socket :8001 --wsgi-file test.py

得到的却是400 badrequest

但是我的nginx跑起来了,http://localhost:8000/static/github1.css是有反应的

terminal的报错是

invalid request block size: 21573 (max 4096)...skip

求大神帮解答

1 个回答
  • 首先你的测试 uwsgi 都没有过 ,先测试好吧

    你的uwsgi端口跟nginx的访问端口也冲突了

    listen 8000; nginx 
    
    server 127.0.0.1:8000; uwsgi
    

    多看看文档: Nginx support


    算了给看下我的在nginx中配置

    server {
        listen       80;
        server_name  repository.pub;
    
        charset utf-8;
    
        #access_log  logs/host.access.log  main;
    
    
        client_max_body_size  75M;
    
        location /static/ {
            alias /home/arch/repository/static/;
        }
    
        location / {
            root    /home/user/repository/repository;
            uwsgi_pass  127.0.0.1:3031;
            include     uwsgi_params;
        }
    

    然后是项目的uwsgi 配置,我这里用的是ini格式

    repository.ini

    [uwsgi]
    socket = 127.0.0.1:3031
    chdir = /home/user/repository/
    wsgi-file = repository/wsgi.py
    processes = 4
    threads = 2
    

    当然配置了uwsgi,则要启动它,别忘了

    2022-10-31 22:34 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有