Search code examples
tensorflownginxflaskcentosuwsgi

Problem serving Flask based applications with uWSGI and Nginx and Tensorflow on CentOS 7


I'm serving an application with Tensorflow. Now I need to serve this flask based application with Ngnix. I used this document on Digitalocean.

Direct serving application with uWSGI is okay but as soon as the service is transferred to Nginx , I get an internal service error (500).

service works fine without Tensorflow and Keras library so I'm pretty sure server config is fine.

myproject.ini:

[uwsgi]
module = wsgi
    
master = true
processes = 5
    
socket = myproject.sock
chmod-socket = 660
vacuum = true

die-on-term = true

/etc/systemd/system/myproject.service:

[Unit]
Description=uWSGI instance to serve myproject
After=network.target
    
[Service]
User=user
Group=nginx
WorkingDirectory=/home/user/myproject
Environment="PATH=/home/user/myproject/myprojectenv/bin"
ExecStart=/home/user/myproject/myprojectenv/bin/uwsgi --ini myproject.ini
    
[Install]
WantedBy=multi-user.target

Thank a lot. Also sorry about my English.


Solution

  • Ok I was tried to change .ini file but that was not work for me. Somethings like to add cheaper = 0 or change processes = 1 and master = false. but somebody told me use gunicorn instead of uWSGI and that's work.

    And that was so easy to switch from uWSGI to Gunicorn. Based on this document on Digitalocean you just need to change

    1. (/etc/systemd/system/myproject.service) this file on line 10 (ExecStart part)
    2. (/etc/nginx/nginx.conf) this file in location part

    ** If you have not configured the server yet, just use this paper

    Hope to be useful. Also sorry about my English.