I got a Web.py app and wanted to push it into production. As recommended by the Web.py Community I decided to use uWSGI and Nginx for this.
My App uses Memcached for Session Storing and MySQL for other storing tasks. The app works fine on my MacBook.
I configured the uWSGI + Nginx setup previously which worked fine. But know I receive a 502 Bad Gateway when I try to access the Index Page on my Ubuntu Server.
BUT: when entering another page I receive all the content I wanted.
In general the app works fine in the Ubuntu environment, as I tested it by typing python app.py 8080
. I was able to enter the page.tld:8080/ and receive all content.
My uWSGI config:
[uwsgi]
gid = www-data
uid = www-data
vhost = true
plugins = python
logdate
#socket = /tmp/uwsgi_vhosts.sock
socket = 127.0.0.1:3031
master = true
processes = 1
harakiri = 120
limit-as = 128
memory-report
no-orphans
The Nginx config:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
# Make site accessible from http://localhost/
server_name page.tld;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:3031;
# This is the absolute path to the folder containing your application
uwsgi_param UWSGI_CHDIR /var/www/page.tld/apps;
# This is actually not necessary for our simple application,
# but you may need this in future
uwsgi_param UWSGI_PYHOME /var/www/page.tld/apps;
# This is the name of your application file, minus the '.py' extension
uwsgi_param UWSGI_SCRIPT test;
}
I keep getting this lines in the vhosts.log of uWSGI:
libgcc_s.so.1 must be installed for pthread_cancel to work
- DAMN ! worker 1 (pid: 1281) died, killed by signal 6 :( trying respawn ...
- Respawned uWSGI worker 1 (new pid: 1330)
Please let me know if you need to see other parts of the configuration.
And these lines in the error.log of nginx:
[error] 1233#0: *1 upstream prematurely closed connection while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: page.tld, request: "GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1:3031", host: "page.tld"
Let me know if any other logs are needed to solve this.
Update: It seems that I get 502 Bad Gateway, when I want to access a page that has to load things from the MySQL Database. But as it is working without uWSGI & NGINX I guess that nginx kills the uwsgi instance for some reason when it tries to load things from the Database.
I recently fixed this problem by setting a higher memory limit within the uwsgi. You will need to restart the uwsgi. I am running uwsgi emperor at start up. So, in my case I rebooted.
System:
Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-43-generic x86_64)
mysqlclient==1.3.6