Reputation: 1741
I have two flask applications that i want to host on the same webserver.
I've successfully got one or the other running, but I can't seem to get both going at the same time.
I used the set-up from http://vladikk.com/2013/09/12/serving-flask-with-nginx-on-ubuntu/
My nginx config and uwsgi ini files are identical; except I substitute a different folder name depending on the app and folder structure, e.g. "request" or "demoapp" for my other app.
my nginx config file for the request app is
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;
}
}
and my uwsgi ini file is
[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
this line gets my app working
/etc/nginx/sites-enabled$ uwsgi --ini /var/www/request/request_uwsgi.ini
and if i switch out "request" for my other app, it get's the other app working.
my nginx error.log shows that when i have both config files in sites-enabled, i get this
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" is the name of my server
I can't find any config examples of anyone running two flask apps or even a good explanation of how to write the conf file.
Update I'm thinking of giving up and setting up a virtual machine with a separate nginx on my server to host the multiple applications.
Thank you!
Upvotes: 0
Views: 761
Reputation: 1829
In nginx you can repeat the server component though change the server_name. Manipulating the server_name can be from a simple dns A Record or CNAME. See https://stackoverflow.com/a/27221427/567606 for a full answer/
Upvotes: 1