ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

子路径上有多个Django Project Nginx

2019-10-11 16:11:14  阅读:167  来源: 互联网

标签:nginx django gunicorn


我试图运行多个用Django编写的仪表板以在服务器上运行,但没有启动并运行它.跟随this digital ocean tutorial并根据this SO answer对其进行了修改.现在一切正常,并且正在运行,但是当指向我的URL时,它将显示Nginx欢迎页面http:// ipaddr / first_dashboard

以下是gunicorn_fdab.socket文件:

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn_fdab.sock

[Install]
WantedBy=sockets.target

以下是gunicorn_fdab.service文件:

[Unit]
Description=gunicorn daemon for fdab
Requires= gunicorn_fdab.socket
After=network.target

[Service]
User=root
Group=root
WorkingDirectory=/opt/fdab
ExecStart=/opt/anaconda/envs/fdab/bin/gunicorn \
          --access-logfile - \
          --workers 3 \
          --bind unix:/run/gunicorn_fdab.sock \
          fdab.wsgi:application

[Install]
WantedBy=multi-user.target

现在这是我的Nginx conf文件:

server {
    listen 80;
    server_name 111.11.11.111;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /opt/fdab/fdab;
    }

    location /fdab {
        include proxy_params;
        rewrite /fdab(.*) $1;
        proxy_pass http://unix:/run/gunicorn_fdab.sock;
    }
}

无法理解在哪里做错了.

如果正在执行curl –unix-socket /run/gunicorn_fdab.sock localhost,则仅返回任何内容.

(base) root@virtualserver01:~# curl --unix-socket /run/gunicorn_fdab.sock localhost
(base) root@virtualserver01:~# 

项目存储在/ opt / fdab.

附加信息:

基本上,我的两个项目的项目结构都如下所示:

/opt/fdab
    /fdab
    /fdab_dashboard


/opt/pdab
    /pdab
    /pdab_dashboard

项目的结构是这样的,因为我打算在fbad和fdab2(第二个项目名称中拥有多个应用程序)中.

编辑

更新了Nginx的conf文件:

server {
    listen 80;
    server_name 111.11.11.111;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /opt/fdab/fdab;
    }

    location /fdab {
        include proxy_params;
        rewrite /fdab/(.*) /$1 break;
        proxy_pass http://unix:/run/gunicorn_fbad.sock;
    }


    location /pdab/static/ {
        alias /opt/pdab/pdab/static/;
    }

    location /pdab {
        include proxy_params;
        rewrite /pdab/(.*) /$1 break;
        proxy_pass http://unix:/run/gunicorn_pdab.sock;
    }

}

现在,我在两个项目中都添加了FORCE_SCRIPT_NAME =’/ exampleproject’.

现在发生的事情是,如果输入http://< ipaddr> / fdab / fdab_dashboard,它可以正常工作,但是如果输入http://< ipaddr> / fdab /或http://< ipaddr> / pdab /,正被重定向到http://< ipaddr> / fdab_dashboard和http://< ipaddr> / pdab_dashboard,而且这不是必需的,而且http://< ipaddr> / fdab_dashboard似乎工作正常.但是网址的fdab部分丢失了,一旦我登录后进入应用程序,该网址似乎就可以了,这可能是因为FORCE_SCRIPT_NAME =’/ fdab’,但是网址http://< ipaddr> / pdab_dashboard给出了我404错误页面.

解决方法:

因此,好消息是您发布的gunicorn和nginx配置看起来正确.

(1)问题1的默认网页显示:

这几乎总是由默认的nginx配置文件default.conf引起的.只需删除该文件,您应该会看到您的网站弹出.唯一要检查的另一件事是测试并重新加载nginx以确保您的配置有效并已加载:

sudo nginx -t
sudo systemctl reload nginx

(2)问题2卷曲到unix套接字没有返回您期望的结果. curl命令看起来有点像:尝试类似:

curl -v --no-buffer --unix-socket /run/gunicorn_fdab.sock http://localhost/route/available/in/django

自今天起-u gunicorn -f,您就可以在将尾花甘蓝原木与journalctl尾随时配对卷曲了

标签:nginx,django,gunicorn
来源: https://codeday.me/bug/20191011/1893541.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有