1.x nginx代理uwsgi请求后端报错, 不走nginx却可以登录

发布于 2022-05-04 16:05:03

目录结构

03.png

nginx配置

events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout 60s;

    #server {
        #listen 80 default_server;
        #server_name _;
        #return 404;
        #}

    # 后端 server
    server {
        listen       8000;
        server_name  dvadmin-django;
        charset utf-8;
        location / {
          root html;
          include  /usr/local/nginx/conf/uwsgi_params;
          uwsgi_pass 0.0.0.0:9000;
          uwsgi_param UWSGI_SCRIPT application.wsgi;
          uwsgi_param UWSGI_CHDIR /data/site/op/backend/; #项目路径
        }
        # Django media
        location /media  {
            root /data/site/op/backend/media;  # your Django project's media files - amend as required
        }
        # Django static
        location /static {
            root /data/site/op/backend/static; # your Django project's static files - amend as required
        }
        access_log /data/logs/backend.access.log;
        error_log  /data/logs/backend.error.log info;
    }
    # 前端配置
    server {
        listen       80;
        server_name  dvadmin-ui;
        charset utf-8;
        location / {
          try_files $uri $uri/ @router; #需要指向下面的@router否则会出现vue的路由在nginx中刷新出现404
          root   /data/site/op/ui/dist/;
          add_header  Cache-Control  max-age=no-cache;
          index  index.html index.php index.htm;
        }
        location ~* \.(css|js|png|jpg|jpeg|gif|gz|svg|mp4|ogg|ogv|webm|htc|xml|woff)$ {
            access_log off;
            add_header Cache-Control max-age=604800;
            root   /data/site/op/ui/dist/;
            index  index.html index.php index.htm;
        }
        location @router {
            rewrite ^.*$ /index.html last;
        }
        access_log /data/logs/ui.access.log;
        error_log  /data/logs/ui.error.log;
    }
}

走nginx的代理(前端.env.production 访问到nginx的8000端口 VUE_APP_BASE_API = 'http://dvadmin-django:8000')

01.png

不走nginx直接访问uwsgi(.env.development里配置的是uwsgi的9000端口

VUE_APP_BASE_API = 'http://dvadmin-django:9000') uwsgi的9000端口
02.png

nginx错误日志

2022/05/04 15:37:35 [error] 19183#0: *8 upstream prematurely closed connection while reading response header from upstream, client: xx.xx.xx.xx, server: dvadmin-django, request: "GET /admin/captcha/refresh/ HTTP/1.1", upstream: "uwsgi://0.0.0.0:9000", host: "dvadmin-django:8000", referrer: "http://dvadmin-ui/"
2022/05/04 15:37:40 [info] 19183#0: *8 client xx.xx.xx.xx closed keepalive connection

查看更多

关注者
0
被浏览
885
1 个回答
liqiang
liqiang python/vue 2022-05-05
这家伙很懒,什么也没写!

dvadmin-backend/application/uwsgi.ini 目录下,修改如下:
image.png

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览