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

时间:2013-10-26 05:25:56

标签: django nginx uwsgi

我真的很难让它正常工作

在我的网站启用文件夹中,我有以下两个.conf文件设置

网站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
        }
    }

网站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
        }
    }

启动uwsgi我运行了以下命令(实际上我运行了一个皇帝命令但是我想在这里一次解决一个问题),当我运行这个站点时A完全正常

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

现在我运行此尝试并启动站点B

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

当我转到ip地址(在网站B上设置)时,它会运行网站django应用程序,但不会拉入css文件

任何想法??

1 个答案:

答案 0 :(得分:2)

我有这个工作,问题是uwsgi_pass

不是传递我相信连接到上游的django变量,而是分别为每个文件将其更改为以下

uwsgi_pass  127.0.0.1:8001;
uwsgi_pass  127.0.0.1:8002;
相关问题