我正在尝试运行多个用 Django 编写的仪表板以在我的服务器上运行,但无法启动并运行它。已关注这个数字海洋教程并根据其进行修改这个答案。现在一切都已启动并正在运行,但是当我指向我的 URL 时,它显示 Nginx 欢迎页面http://ipaddr/first_dashboard
下面是gunicorn_fdab.socket
file :
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn_fdab.sock
[Install]
WantedBy=sockets.target
下边是gunicorn_fdab.service
file :
[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(第二个项目名称.
EDIT
更新了 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/
or http://<ipaddr>/pdab/
,我被重定向到http://<ipaddr>/fdab_dashboard
and http://<ipaddr>/pdab_dashboard
,这不是所要求的,而且,http://<ipaddr>/fdab_dashboard
似乎工作正常。但是fdab
部分网址丢失,登录后进入应用程序后,网址看起来不错,可能是因为FORCE_SCRIPT_NAME = '/fdab'
,但是网址http://<ipaddr>/pdab_dashboard
给我404 error
page.