在ubuntu上为多个uwsgi-emperor flask应用程序配置nginx

时间:2015-05-07 18:13:25

标签: python ubuntu nginx flask uwsgi

我想在同一个网络服务器上托管两个烧瓶应用程序。我已经成功地运行了一个或另一个,但我似乎无法同时进行。

我使用了来自http://vladikk.com/2013/09/12/serving-flask-with-nginx-on-ubuntu/

的设置

我的nginx配置和uwsgi ini文件完全相同;除了我根据应用程序和文件夹结构替换不同的文件夹名称,例如我的其他应用程序的“请求”或“demoapp”。

我的请求应用程序的nginx配置文件是

server {
    listen      80;
    server_name localhost;
    charset     utf-8;
    client_max_body_size 75M;

    location / { try_files $uri @yourapplication; }
    location @yourapplication {
        include uwsgi_params;
        uwsgi_pass unix:/var/www/request/request_uwsgi.sock;
    }
}

我的uwsgi ini文件是

[uwsgi]
#application's base folder
base = /var/www/request

#python module to import
app = open
module = %(app)

home = %(base)/venv
pythonpath = %(base)

#socket file's location
socket = /var/www/request/%n.sock

#permissions for the socket file
chmod-socket    = 666

#the variable that holds a flask application inside the module imported at line #6
callable = app

#location of log files
logto = /var/log/uwsgi/%n.log

此行让我的应用正常工作

/etc/nginx/sites-enabled$ uwsgi --ini /var/www/request/request_uwsgi.ini


如果我为我的其他应用程序切换出“请求”,那么另一个应用就会正常工作。

我的nginx error.log显示当我在启用网站的情况下同时拥有两个配置文件时,我得到了这个

2015/05/07 10:03:45 [warn] 7527#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2015/05/07 10:03:45 [warn] 7527#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2015/05/07 10:03:46 [warn] 7531#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2015/05/07 10:03:46 [warn] 7531#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2015/05/07 10:04:06 [error] 7533#0: *1 connect() to unix:/var/www/demoapp/demoapp_uwsgi.sock failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /login HTTP/1.1", upstream: "uwsgi://unix:/var/www/demoapp/demoapp_uwsgi.sock:", host: "argonaut"
2015/05/07 10:04:08 [error] 7533#0: *1 connect() to unix:/var/www/demoapp/demoapp_uwsgi.sock failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /login HTTP/1.1", upstream: "uwsgi://unix:/var/www/demoapp/demoapp_uwsgi.sock:", host: "argonaut"
2015/05/07 10:30:10 [error] 7788#0: *1 open() "/usr/share/nginx/html/login" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /login HTTP/1.1", host: "argonaut"
2015/05/07 10:31:54 [error] 7833#0: *1 open() "/usr/share/nginx/html/request" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /request HTTP/1.1", host: "argonaut"

“argonaut”是我服务器的名称

我找不到任何运行两个烧瓶应用的人的配置示例,甚至找不到如何编写conf文件的详细说明。

更新 我正在考虑放弃并设置一个虚拟机,在我的服务器上使用单独的nginx来托管多个应用程序。

谢谢!

1 个答案:

答案 0 :(得分:1)

在nginx中,您可以通过更改server_name重复服务器组件。操作server_name可以来自简单的dns A Record或CNAME。有关完整答案/

,请参阅https://stackoverflow.com/a/27221427/567606