uWSGI 虚拟主机问题

6 投票
4 回答
3493 浏览
提问于 2025-04-16 12:06

uWSGI 配置

[uwsgi]
socket = /tmp/uwsgi.sock
chmod-socket = 666
processes = 1
master = true
vhost = true
no-site = true

Nginx 配置

server {
    listen       80;
    server_name  www.site1.com;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/tmp/uwsgi.sock;
        uwsgi_param UWSGI_PYHOME /var/virtualenvs/site1;
        uwsgi_param UWSGI_CHDIR /var/www/site1;
        uwsgi_param UWSGI_SCRIPT wsgi;
    }
}

server {
    listen       80;
    server_name  www.site2.com;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/tmp/uwsgi.sock;
        uwsgi_param UWSGI_PYHOME /var/virtualenvs/site2;
        uwsgi_param UWSGI_CHDIR /var/www/site2;
        uwsgi_param UWSGI_SCRIPT wsgi;
    }
}

我访问的第一个网站总是显示在屏幕上,所以如果我先去访问 site2,就再也看不到 site1 了。有没有人知道为什么 uWSGI 的虚拟主机设置好像不管用?

4 个回答

0

如果你想使用TCP连接,或者你的nginx是没有uwsgi_pass支持的版本:

nginx的配置文件:

location / {
    proxy_pass http://127.0.0.1:8010/;
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

uwsgi的配置文件:

[uwsgi]
# set the http port
http = :8010
2

在这里 http://wiki.nginx.org/HttpUwsgiModuleMultipleDynamicApplications 你可以找到一个例子,教你如何通过一个单一的上游(upstream)来设置多个uWSGI应用。

5

问题是,使用INI配置文件会导致uWSGI以单个解释器模式运行。而如果使用相同的配置但换成XML格式,就能正常工作。uWSGI的开发者表示,以后版本中不会再出现这个问题。

撰写回答