Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start uwsgi with flask and nginx

Tags:

nginx

flask

uwsgi

I guess my main problem is that i don't know, how file hierarchy should look like ? So far i was following Grinberg's tutorial in his "Flask development" book. So i have like:

--manage.py ( Flask's Script extension script)
--app/   ( application folder as a package)
--virtual_env

and not sure what all i messed up, but now when i try whatever with uwsgi command , it says following error :

current working directory: /home/gaucan/temp/my_app
detected binary path: /usr/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***

EDIT: starting it like this worked:

uwsgi --http :9090 -w manage:app --enable-threads

this worked ... in manage.py i had line: app=create_app('default') so that was pretty much all i guess i needed to do...

but i still cant get anyhow get rid of warning above... that i am running uwsgi without its master process manager... is it OK ? or have i done wrong something?

this is just created /etc/nginx/nginx.conf file

    worker_processes 1;

events {

     worker_connections 1024;

}

http {

sendfile on;

gzip              on;
gzip_http_version 1.0;
gzip_proxied      any;
gzip_min_length   500;
gzip_disable      "MSIE [1-6]\.";
gzip_types        text/plain text/xml text/css
                  text/comma-separated-values
                  text/javascript
                  application/x-javascript
                  application/atom+xml;

# Configuration containing list of application servers
upstream uwsgicluster {

    server 127.0.0.1:8080;
    # server 127.0.0.1:8081;
    # ..
    # .

}

# Configuration for Nginx
server {

    # Running port
    listen 80;

    # Settings to by-pass for static files 
    location ^~ /static/  {

        # Example:
        # root /full/path/to/application/static/file/dir;
        root /app/static/;

    }

    # Serve a static file (ex. favico) outside static dir.
    location = /favico.ico  {

        root /app/favico.ico;

    }

    # Proxying connections to application servers
    location / {

        include            uwsgi_params;
        uwsgi_pass         uwsgicluster;

        proxy_redirect     off;
        proxy_set_header   Host $host;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Host $server_name;

    }
}

}

like image 589
waTEXmelon Avatar asked Mar 07 '15 09:03

waTEXmelon


People also ask

How do you run uWSGI Flask?

The most basic way to run uWSGI is to tell it to start an HTTP server and import your application. If you're using the app factory pattern, you'll need to create a small Python file to create the app, then point uWSGI at that.

How do I start uWSGI service?

Get the uwsgi services to work fine, like by using: sudo systemctl start uwsgi and validating with sudo systemctl status uwsgi. Get nginx to work OK, validating via sudo nginx -t , sudo systemctl start nginx , and sudo systemctl status nginx.


1 Answers

This is probably related to how you installed uwsgi. This warning:

!!! no internal routing support, rebuild with pcre support !!!

has nothing to do with your application, it is about your uwsgi binary.

Basically it says that one part of uwsgi has not been enabled in the binary that you are using. That specific functionality is not needed to run your Flask application, so you can ignore the warning. But if you want to learn more, see this question for some information about this problem and how to solve it.

Now, regarding this other warning:

*** WARNING: you are running uWSGI without its master process manager ***

I think you are missing the --master option, to enable the prefork server.

like image 168
Miguel Avatar answered Sep 27 '22 22:09

Miguel