简体   繁体   English

如何使用Django nginx和uwsgi设置多个网站?

[英]How to setup multiple websites with Django nginx and uwsgi?

I'm really having a tough time getting this to work properly 我真的很难让它正常工作

In my sites enabled folder I have the following two .conf files setup 在我的网站启用文件夹中,我有以下两个.conf文件设置

Site A (this site I setup first and works properly): 站点A(此站点我先设置并正常工作):

# the upstream component nginx needs to connect to
upstream django {
    server 127.0.0.1:8001; # for a web port socket (we'll use this first)
    }

# configuration of the server
server {

    # the port your site will be served on
    listen  80;
    # the domain name it will serve for
    server_name databank.eaventures.co www.databank.eaventures.co ; # substitute your mac$
    charset     utf-8;
    access_log /srv/www/*****/logs/access.log;
    error_log /srv/www/*****/logs/error.log;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias /srv/www/******/projectdatabank/media;  # your Django project's m$
    }

    location /static {
        alias /srv/www/******/projectdatabank/static; # your Django project's s$
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
        }
    }

Site B (the new site I am trying to add but not getting to work): 站点B(我试图添加但未开始工作的新站点):

# the upstream component nginx needs to connect to
upstream django2 {
    server 127.0.0.1:8002; # for a web port socket (we'll use this first)
    }

# configuration of the server
server {
    # the port your site will be served on
    listen  80;
    # the domain name it will serve for
    server_name 50.116.47.120 ***.eaventures.co ; # substitute your machine's IP add$
    charset     utf-8;
    access_log /srv/www/***.capital.com/logs/access.log;
    error_log /srv/www/***capital.com/logs/error.log;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias /srv/www/***capital.com/***/media;  # your Django project's media$
    }

    location /static {
        alias /srv/www/***capital.com/***/static; # your Django project's stati$
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
        }
    }

to start uwsgi I ran the following command (in actuality I run an emperor command however I'd like to tackle one issue at a time here), when I run this site A works completely fine 启动uwsgi我运行了以下命令(实际上我运行了一个皇帝命令但是我想在这里一次解决一个问题),当我运行这个网站时A完全正常

uwsgi --socket :8001 --chdir /srv/www/.com/projectdatabank/ --wsgi-file /srv/www/.com/projectdatabank/databank/wsgi.py

Now I run this to try and start site B 现在我运行它来尝试启动站点B.

uwsgi --socket :8002 --chdir /srv/www/***capital.com/***/ --wsgi-file /srv/www/***capital.com/***/***/wsgi.py

When I go to the ip address (set on site B) it runs the site django app but does not pull in the css files 当我转到IP地址(在网站B上设置)它运行网站django应用程序但不拉入css文件

any thoughts?? 有什么想法吗??

I got this working, the problem was the uwsgi_pass 我得到了这个工作,问题是uwsgi_pass

Instead of passing the django variable which I believe is connected to the upstream, i changed it to the following for each file respectively 而不是传递我相信连接到上游的django变量,我分别将它更改为每个文件的以下内容

uwsgi_pass  127.0.0.1:8001;
uwsgi_pass  127.0.0.1:8002;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM