forked from orbit-oss/flask
Merge pull request #1558 from JonasGroeger/master
Update uwsgi/nginx deployment documentation
This commit is contained in:
commit
751fe451df
1 changed files with 18 additions and 9 deletions
|
|
@ -29,36 +29,45 @@ Given a flask application in myapp.py, use the following command:
|
||||||
|
|
||||||
.. sourcecode:: text
|
.. sourcecode:: text
|
||||||
|
|
||||||
$ uwsgi -s /tmp/uwsgi.sock --module myapp --callable app
|
$ uwsgi -s /tmp/uwsgi.sock --manage-script-name --mount /yourapplication=myapp:app
|
||||||
|
|
||||||
Or, if you prefer:
|
Or, if you prefer:
|
||||||
|
|
||||||
.. sourcecode:: text
|
.. sourcecode:: text
|
||||||
|
|
||||||
$ uwsgi -s /tmp/uwsgi.sock -w myapp:app
|
$ uwsgi -s /tmp/uwsgi.sock --manage-script-name --mount /yourapplication=myapp:app
|
||||||
|
|
||||||
|
The ``--manage-script-name`` will move the handling of ``SCRIPT_NAME`` to
|
||||||
|
uwsgi, since its smarter about that. It is used together with the ``--mount``
|
||||||
|
directive which will make requests to ``/yourapplication`` be directed to
|
||||||
|
``myapp:app``, where ``myapp`` refers to the name of the file of your flask
|
||||||
|
application (without extension). ``app`` is the callable inside of your
|
||||||
|
application (usually the line reads ``app = Flask(__name__)``.
|
||||||
|
|
||||||
|
If you want to deploy your flask application inside of a virtual environment,
|
||||||
|
you need to also add ``--virtualenv /path/to/virtual/environment``. You might
|
||||||
|
also need to add ``--plugin python`` or ``--plugin python3`` depending on which
|
||||||
|
python version you use for your project.
|
||||||
|
|
||||||
Configuring nginx
|
Configuring nginx
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
A basic flask uWSGI configuration for nginx looks like this::
|
A basic flask nginx configuration looks like this::
|
||||||
|
|
||||||
location = /yourapplication { rewrite ^ /yourapplication/; }
|
location = /yourapplication { rewrite ^ /yourapplication/; }
|
||||||
location /yourapplication { try_files $uri @yourapplication; }
|
location /yourapplication { try_files $uri @yourapplication; }
|
||||||
location @yourapplication {
|
location @yourapplication {
|
||||||
include uwsgi_params;
|
include uwsgi_params;
|
||||||
uwsgi_param SCRIPT_NAME /yourapplication;
|
uwsgi_pass unix:/tmp/yourapplication.sock;
|
||||||
uwsgi_modifier1 30;
|
|
||||||
uwsgi_pass unix:/tmp/uwsgi.sock;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
This configuration binds the application to ``/yourapplication``. If you want
|
This configuration binds the application to ``/yourapplication``. If you want
|
||||||
to have it in the URL root it's a bit simpler because you don't have to tell
|
to have it in the URL root its a bit simpler::
|
||||||
it the WSGI ``SCRIPT_NAME`` or set the uwsgi modifier to make use of it::
|
|
||||||
|
|
||||||
location / { try_files $uri @yourapplication; }
|
location / { try_files $uri @yourapplication; }
|
||||||
location @yourapplication {
|
location @yourapplication {
|
||||||
include uwsgi_params;
|
include uwsgi_params;
|
||||||
uwsgi_pass unix:/tmp/uwsgi.sock;
|
uwsgi_pass unix:/tmp/yourapplication.sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
.. _nginx: http://nginx.org/
|
.. _nginx: http://nginx.org/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue