I am trying to run a Flask application on nginx with uWSGI on my Ubuntu droplet following this tutorial.
All the intermediate tests work fine until the very last one, where it's time to test all components working together.
Here is where the Flask app lives.
dsaltares@saltares:/home/dsaltares/conjugate/site: tree .
.
├── conjugate.ini
├── conjugate.py
├── conjugate.sock
├── wsgi.py
The relevant parts in conjugate.py
bp = Blueprint('bp', name, template_folder='templates')
application = Flask(__name__)
application.config['APPLICATION_ROOT'] = '/conjugate'
application.register_blueprint(bp, url_prefix='conjugate')
@bp.route('/')
def index():
return render_template('index.html')
The wsgi.py
file
from conjugate import application
if __name__ == '__main__':
application.run()
The conjugate.ini
file
[uwsgi]
module = wsgi
master = true
processes = 5
socket = conjugate.sock
chmod-socket = 660
vacuum = true
die-on-term = true
uid = dsaltares
gid = www-data
Running uwsgi --socket 0.0.0.0:8000 --protocol=http -w wsgi
works perfectly fine. I can access the app from my laptop.
The /etc/init/conjugate.conf
file
description "uWSGI server instance configured to serve conjugate"
start on runlevel [2345]
stop on runlevel [!2345]
setuid dsaltares
setgid www-data
env PATH=/home/dsaltares/conjugate/env/bin
chdir /home/dsaltares/conjugate/site
exec uwsgi --ini conjugate.ini
Now the /etc/nginx/sites-available/default
file
server {
listen 80;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
root /usr/share/nginx/html;
index index.html index.htm index.nginx-debian.html index.php;
server_name example.com;
location = / {
# Redirect to /blog
return 301 http://example.com/blog;
}
location /blog/ {
try_files $uri $uri/ /blog/index.php?$args;
}
location ~ /\.ht {
deny all;
}
location ~ \.php$ {
...
}
location /conjugate/ {
include uwsgi_params;
uwsgi_pass unix:/home/dsaltares/conjugate/site/conjugate.sock;
}
}
After sudo service conjugate restart
and sudo service nginx restart
and trying to access http://example.com/conjugate
I get:
404 The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
sudo tail -f /var/log/nginx/error.log
doesn't show any errors.
Any ideas? Thank you very much