From 43a0c63169d4c654b7338a38b4723e017136d719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Thu, 9 Oct 2014 20:37:27 +0200 Subject: [PATCH] Proxies --- ...=> 2014-09-23-publishing-in-pypi.markdown} | 2 +- _posts/2014-10-09-proxies.markdown | 67 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) rename _posts/{2014-10-23-publishing-in-pypi.markdown => 2014-09-23-publishing-in-pypi.markdown} (99%) create mode 100644 _posts/2014-10-09-proxies.markdown diff --git a/_posts/2014-10-23-publishing-in-pypi.markdown b/_posts/2014-09-23-publishing-in-pypi.markdown similarity index 99% rename from _posts/2014-10-23-publishing-in-pypi.markdown rename to _posts/2014-09-23-publishing-in-pypi.markdown index 633eee1..366f81f 100644 --- a/_posts/2014-10-23-publishing-in-pypi.markdown +++ b/_posts/2014-09-23-publishing-in-pypi.markdown @@ -1,7 +1,7 @@ --- layout: post title: "Publishing in PyPi" -date: 2014-10-27 10:00:00 +date: 2014-09-27 10:00:00 tags: github python pypi --- diff --git a/_posts/2014-10-09-proxies.markdown b/_posts/2014-10-09-proxies.markdown new file mode 100644 index 0000000..5a3f81e --- /dev/null +++ b/_posts/2014-10-09-proxies.markdown @@ -0,0 +1,67 @@ +--- +layout: post +title: "Proxies with Apache and python" +date: 2014-10-09 10:00:00 +tags: python apache proxy gunicorn uwsgi +--- + +This is a quick note on proxying a local python application (e.g. flask) to a subdirectory in Apache. +This assumes that the file wsgi.py contains a WSGI application with the name *application*. Hence, wsgi:application. + +## Gunicorn +{% highlight apache %} + + ProxyPass http://127.0.0.1:8888/myapp/ + ProxyPassReverse http://127.0.0.1:8888/myapp/ + RequestHeader set SCRIPT_NAME "/myapp/" + +{% endhighlight %} + +**Important**: *SCRIPT_NAME* and the end of *ProxyPass* URL **MUST BE THE SAME**. Otherwise, Gunicorn will fail miserably. + +Try it with: +{% highlight bash %} +venv/bin/gunicorn -w 4 -b 127.0.0.1:8888 --log-file - --access-logfile - wsgi:application +{% endhighlight %} + + +## UWSGI +This is a very simple configuration. I will try to upload one with more options for uwsgi (in a .ini file). + +{% highlight apache %} + + SetHandler uwsgi_handler + uWSGISocker 127.0.0.1:8888 + +{% endhighlight %} + +Try it with: + +{% highlight bash %} +uwsgi --socket 127.0.0.1:8888 -w wsgi:application +{% endhighlight %} + +### Extra: Supervisor +If everything went as expected, you can wrap your command in a supervisor config file and let it handle the server for you. +{% highlight ini %} +[unix_http_server] +file=/tmp/myapp.sock ; path to your socket file + +[supervisord] +logfile = %(here)s/logs/supervisor.log +childlogdir = %(here)s/logs/ + +[rpcinterface:supervisor] +supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface + +[supervisorctl] +logfile = %(here)s/logs/supervisorctl.log +serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket + + +[program:myapp] +command = venv/bin/gunicorn -w 4 -b 0.0.0.0:5000 --log-file %(here)s/logs/gunicorn.log --access-logfile - wsgi:application +directory = %(here)s +environment = PATH=%(here)s/venv/bin/ +logfile = %(here)s/logs/myapp.log +{% endhighlight %}