django项目,配值nginx 和 awsgi ,POST 不起作用,请教!

弄好了,发现是 ip地址写错了一个数字而已,唉
<python manage.py runserver 项目可以正常启动>
nginx 监听两个端口 80和9000:

# nginx 监听80端口
server {
    listen 80;
    listen [::]:80;
    server_name localhost;
    charset  utf-8;
    location / {
        root /home/index/general_office/dist;
        index index.html index.htm;
        autoindex_localtime on;
    }
    error_page 404 /40x.html;
    location = /40x.html {
        root /home/index/error_page/html;
    }
}

浏览器测试: http://11.111.111.11/ 正常进入主页

# nginx 监听9000端口  (接收前端 axios请求的端口)
server {
    listen 9000;
    server_name 11.111.111.11;
    charset utf-8;
    client_max_body_size 5M; 
    location / {
        uwsgi_pass 127.0.0.1:9001; # 转发给 uwsgi  和  django
        include /etc/nginx/uwsgi_params;
    }
}

浏览器测试: http://11.111.111.11:9000/ 正常进入 django 项目的主页,说明 nginx 对 9000端口转发 uwsgi 正常

# uwsgi 监听 127.0.0.1:9001  接收nigex的转发,并回转
[uwsgi]
socket=127.0.0.1:9001
chdir=/home/backend/general_server
wsgi-file=%(chdir)/general_server/wsgi.py
buffer-size=65535
process=6
threads=2
pidfile=uwsgi.pid
daemonize=uwsgi.log
mastar=True

问题描述:
这里我点主页登录, 怎么样都没用处,
nginx 中的 access.log 文件没有 post 日志
uwsgin.log里也没有日志
感觉post 不起作用,请教解决方法

img

#nginx 和 uwsgi 放在同一容器,生成代码如下
docker run -it --name django-nginx1.0 --hostname django-nginx1.0 --restart always --network host
 -v /home/nginx/nginx.conf:/etc/nginx/nginx.conf:ro 
 -v /home/static:/home/static
 -v /home/code/index:/home/index 
 -v /home/code/backend:/home/backend   
 -v /home/nginx/conf.d:/etc/nginx/conf.d  --privileged=true
 django-nginx:1.0  /bin/bash   # django-nginx:1.0 自制镜像名

跨域了,不能这么干

  1. 如果你一定要这么干就参考这边文章,关键字是django 开启跨域
    解决django跨域问题_wuyepiaoxue789的博客-CSDN博客_django 跨域
  2. 正确的做法,django提供的接口都加上api,在80端口把path=/api的请求转发到django
    server {
     listen 80;
     listen [::]:80;
     server_name localhost;
     charset  utf-8;
     location / {
         root /home/index/general_office/dist;
         index index.html index.htm;
         autoindex_localtime on;
     }
     location /api {
         uwsgi_pass 127.0.0.1:9001; # 转发给 uwsgi  和  django
         include /etc/nginx/uwsgi_params;
     }
     error_page 404 /40x.html;
     location = /40x.html {
         root /home/index/error_page/html;
     }
    }
    

第一,请求没到nginx,
第二,nginx配置有问题,

可以从这两方面检查,可以解决你的你问题

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632