如何解决如何在单个服务器上使用 uWSGI 和 NGINX 在子域下托管多个 Django 项目? A.conf 从 /home/ubuntu/ProjA/nginx/A.conf 符号链接到 /etc/nginx/sites-enabled/AB.conf 从 /home/ubuntu/ProjB/nginx/B.conf 符号链接到 /etc/nginx/sites-enabled/B
我一直在尝试使用 uWSGI 和 Unix socket Nginx 在单个服务器上部署两个 Django 项目,我已经交叉检查了配置,它看起来不错,但它的行为很奇怪。让我给项目名称 A 作为第一个,B 作为第二个,以便更好地理解和参考。
对于这两个项目,我已经按照这篇出色的文章 How To Serve Multiple Django Applications with uWSGI and Nginx in Ubuntu 20.04
设置了 uWSGI 和 Nginx一切正常 emperor.uwsgi.service
显示了每个项目 A 和 B 的两个 uwsgi 进程。正确路径中有套接字文件。但是当我尝试使用不同的子域同时提供服务时,假设为 A 子域 A.example.com 和 B 子域 B .example.com 在端口 80 使用 Nginx 然后 A.example.com 工作正常,但 B.example.com 返回默认的 Nginx 页面。尽管如此,如果我更改 、B.example.com 的 配置并使用端口 8000,它在 B.example.com:8000 上工作正常.
A.conf 从 /home/ubuntu/ProjA/nginx/A.conf 符号链接到 /etc/nginx/sites-enabled/A
upstream A_uwsgi {
server unix:///run/uwsgi/A.sock fail_timeout=0;
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name A.example.com;
# charset utf-8;
# max upload size
client_max_body_size 5M;
access_log /home/ubuntu/ProjA/logs/nginx-access.log;
error_log /home/ubuntu/ProjA/logs/nginx-error.log;
# conf for letsencrypt ssl
include /home/ubuntu/ProjA/nginx/letsencrypt.conf;
# Not using since handled via google static storage
# Django media
location /media {
alias /home/ubuntu/ProjA/media;
}
location /static {
alias /home/ubuntu/ProjA/static;
}
# non-media requests handled by uwsgi
location / {
include /home/ubuntu/ProjA/uwsgi/uwsgi_params; # the uwsgi_params file you installed
uwsgi_pass A_uwsgi;
}
}
B.conf 从 /home/ubuntu/ProjB/nginx/B.conf 符号链接到 /etc/nginx/sites-enabled/B
upstream B_uwsgi {
server unix:///run/uwsgi/B.sock fail_timeout=0;
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name B.example.com;
# charset utf-8;
# max upload size
client_max_body_size 5M;
access_log /home/ubuntu/ProjB/logs/nginx-access.log;
error_log /home/ubuntu/ProjB/logs/nginx-error.log;
# conf for letsencrypt ssl
include /home/ubuntu/ProjB/nginx/letsencrypt.conf;
# Not using since handled via google static storage
# Django media
location /media {
alias /home/ubuntu/ProjB/media;
}
location /static {
alias /home/ubuntu/ProjB/static;
}
# non-media requests handled by uwsgi
location / {
include /home/ubuntu/ProjB/uwsgi/uwsgi_params; # the uwsgi_params file you installed
uwsgi_pass B_uwsgi;
}
}
因此,根据上述配置,网站 A.example.com 就像一个魅力,但不是 B.example.com
但是如果我在 B.conf
中更改监听端口...
server {
# the port your site will be served on
listen 8000;
# the domain name it will serve for
server_name B.example.com;
...
然后它适用于 B.example.com:8000
我浏览了很多文章,但没有达到我想要的效果。也许我错过了一些东西。我在几个服务器上手动和自动脚本尝试了几次,但被相同的行为拉了下来。
评论所需的任何其他附加信息。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。