I am running a flask application using uwsgi and using nginx to serve the content.
vassal ini file:
[uwsgi]
chdir = /var/www/html/PyNLP/
;emperor = /var/www/html/PyNLP/
module = nltk_endpoint:app
master = true
processes = 5
socket = /tmp/PyNLP.sock
virtualenv = /var/www/html/PyNLP/nltkenv
mount = /PyNLP=nltk_endpoint:app
chmod-socket = 666
uid = www-data
gid = www-data
vacuum = true
die-on-term = true
enable-threads = true
;harakiri = 300
;buffer-size=65535
The project is contained in /var/www/html/PyNLP and contains the file nltk_endpoint.py along with the above .ini file
Now, when I run it without emperor:
uwsgi --ini PyNLP.ini --manage-script-name
It seems to be working fine when I try to access this flask API via a postman POST request. The URL looks like:
http://myIP:81/PyNLP/spellCheck
The first part /PyNLP is the mount point for the flask application and the last part /spellCheck is an app route in the project:
@app.route("/spellCheck", methods=["POST"])
def spellCheck():
req = request.get_json()
resp = jsonify(spell_check(req['text']))
return resp
The nginx config looks like:
location = /PyNLP { rewrite ^ /PyNLP/; }
location /PyNLP { try_files $uri @PyNLP; }
location @PyNLP {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
include uwsgi_params;
uwsgi_pass unix:/tmp/PyNLP.sock;
}
Without emperor this works just fine. But when I try to use:
uwsgi --emperor emperor/emperor.ini --manage-script-name
I get a 404 error for the url path on postman
Emperor ini file:
[uwsgi]
;emperor-tyrant = true
;emperor = %dvassals
;emperor-pidfile = %demperor.pid
;emperor-stats = %demperor.stat.sock
;vassals-include = %dvassals-default.ini
;touch-logrotate = %p
;touch-reload = %p
;touch-reload = %dvassals-default.ini
;log-date = true
;log-truncate = true
;logto =
emperor = /var/www/html/PyNLP/
;chdir = /var/www/html/PyNLP/
;mount = /PyNLP=nltk_endpoint:app
;buffer-size=65535
uid = www-data
gid = www-data
vacuum = true
die-on-term = true
uwsgi log for this request was :
[pid: 9812|app: 0|req: 1/1] 111.125.198.234 () {48 vars in 841 bytes} [Tue Jan 23 10:49:17 2018] POST /PyNLP/spellCheck => generated 233 bytes in 5 msecs (HTTP/1.1 404) 2 headers in 72 bytes (1 switches on core 0)announcing my loyalty to the Emperor...
and nginx/error.log as :
*43 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 111.125.198.234, server: _, request: "POST /PyNLP/spellCheck HTTP/1.1", upstream: "uwsgi://unix:/tmp/PyNLP.sock:", host: "XX.XX.XX.XX:81"
Similar questions on stackoverflow suggested either to change buffer-size in ini files, which did not help as well as to verify if post body is handled correctly, which I think is fine as well, since it worked with POST request just fine without emperor. I suspect it may be a mount or url path issue or a permission issue, but cant figure out why this wont work with emperor. Any ideas? Thanks in advance.