如何在单个服务器上使用uWSGI和NGINX在子域下托管多个Django项目?
我一直在尝试使用uWSGI和unixsocketnginx在一台服务器上部署两个Django项目,我反复检查了配置,它看起来很好,但行为异常。为了更好地理解和参考,让我给第一个项目命名为A,第二个项目命名为B 对于这两个项目,我都按照这篇优秀的文章设置了uWSGI和Nginx设置 一切正常如何在单个服务器上使用uWSGI和NGINX在子域下托管多个Django项目?,django,nginx,uwsgi,nginx-reverse-proxy,nginx-config,Django,Nginx,Uwsgi,Nginx Reverse Proxy,Nginx Config,我一直在尝试使用uWSGI和unixsocketnginx在一台服务器上部署两个Django项目,我反复检查了配置,它看起来很好,但行为异常。为了更好地理解和参考,让我给第一个项目命名为A,第二个项目命名为B 对于这两个项目,我都按照这篇优秀的文章设置了uWSGI和Nginx设置 一切正常emperor.uwsgi.service为每个项目A和B显示了两个uwsgi流程。套接字文件位于正确的路径。但是,当我尝试使用不同的子域为这两个域提供服务时,比方说,对于A子域A.example.com和B.
emperor.uwsgi.service
为每个项目A和B显示了两个uwsgi流程。套接字文件位于正确的路径。但是,当我尝试使用不同的子域为这两个域提供服务时,比方说,对于A子域A.example.com和B.example.com子域B.example.com在端口80使用Nginx,那么A.example.com效果很好,但是B.example.com返回默认的Nginx页面。尽管如此,如果我更改,B.example.com的配置并使用端口8000,它在B.example.com:8000上工作正常
A.conf符号链接到/etc/nginx/sites enabled/A from/home/ubuntu/ProjA/nginx/A.conf
B.conf从/home/ubuntu/ProjB/nginx/B.conf链接到/etc/nginx/sites enabled/B
因此,根据上面的配置,站点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
我读了很多文章,但没有达到我想要的。也许我错过了什么。我在几个服务器上尝试了几次手动和自动脚本,但都是通过相同的行为实现的
评论所需的任何其他信息。在这两种情况下,您的nginx和uWSGI日志中显示了什么?
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;
}
}
...
server {
# the port your site will be served on
listen 8000;
# the domain name it will serve for
server_name B.example.com;
...