【发布时间】:2019-09-02 11:18:34
【问题描述】:
我正在尝试运行多个用 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 配置文件:
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 似乎工作正常。但是 url 的 fdab 部分丢失了,一旦我登录后进入应用程序,url 似乎很好,可能是因为 FORCE_SCRIPT_NAME = '/fdab' ,但是 url http://<ipaddr>/pdab_dashboard 给了我404 error 页面。
【问题讨论】:
-
您的 conf 文件是否在启用站点的文件夹中?
-
我在
/etc/nginx文件夹中有nginx.conf。在站点启用中,我有dashboard和default文件。我刚刚通过删除rewrite指令并将位置设置为/来检查它,并且Django 应用程序正在运行。所以我认为这只是 Nginx 配置的问题。 -
据我所知,在 /fdab 块中,您通过删除路径的 /fdab 部分来重定向请求,但您没有 / 的位置块。所以当一个请求像这样到达时:/fdab/abc,它将被重定向到/abc,但是这里没有位置块处理
-
我在 Nginx conf 方面没有太多专业知识。我尝试了上面提到的 SO 答案以及 DigitalOcean 教程中的评论之一,也谈到了同样的问题。您知道如何实现吗?
-
你能把“location /fdab”改成“location /”,并保持重写吗?