2019-01-10 18:35:05 +00:00
<!DOCTYPE html>
< html >
< head >
< meta charset = "utf-8" >
< meta http-equiv = "X-UA-Compatible" content = "IE=edge,chrome=1" >
< title > Balkian' s site - WELCOME< / title >
< meta name = "viewport" content = "width=device-width" >
< link rel = "stylesheet" href = "../../font-awesome/css/all.css" >
< link rel = "stylesheet" media = "only screen" href = "../../css/main.css" >
< link href = 'http://fonts.googleapis.com/css?family=Open+Sans:300|Comfortaa' rel = 'stylesheet' type = 'text/css' >
< / head >
< body >
< div id = "container" class = "container" >
< div id = "contentwrapper" >
< div id = "content" >
< header id = "header" >
< ul class = "navbar" id = "navbar" >
< a href = "../../" >
< li >
< i class = "fa fa-home fa-large" > < / i >
< / li > < / a >
2019-01-11 14:45:46 +00:00
< a href = "../../post/" > < li class = '' > Blog
2019-01-10 18:35:05 +00:00
< / li > < / a >
< a href = "../../tags/" > < li class = '' > Tags
< / li > < / a >
< a href = "../../cheatsheet/" > < li class = '' > Cheatsheets
< / li > < / a >
< a href = "../../project/" > < li class = '' > Projects
< / li > < / a >
2019-01-11 14:45:46 +00:00
< a href = "../../page/todo/" > < li class = '' > To-do
< / li > < / a >
2019-01-10 18:35:05 +00:00
< a href = "//jfernando.es" target = "_blank" > < li >
CV
< / li > < / a >
2019-01-11 14:45:46 +00:00
< a href = "../../search" > < li >
< i class = "fa fa-search" > < / i >
< / li > < / a >
2019-01-10 18:35:05 +00:00
< / ul >
< / header >
< h2 > Proxies with Apache and python< / h2 >
< span class = "date" > 2014/10/09< / span >
< span >
< a class = "tag" href = '../../tags/python' > < span class = "label" > python< / span > < / a >
< a class = "tag" href = '../../tags/apache' > < span class = "label" > apache< / span > < / a >
< a class = "tag" href = '../../tags/proxy' > < span class = "label" > proxy< / span > < / a >
< a class = "tag" href = '../../tags/gunicorn' > < span class = "label" > gunicorn< / span > < / a >
< a class = "tag" href = '../../tags/uwsgi' > < span class = "label" > uwsgi< / span > < / a >
< / span >
< h3 > < / h3 >
< p > 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 < em > application< / em > . Hence, wsgi:application.< / p >
< h2 id = "gunicorn" > Gunicorn< / h2 >
< div class = "highlight" > < div style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4" >
< table style = "border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;" > < tr > < td style = "vertical-align:top;padding:0;margin:0;border:0;" >
2019-12-11 13:32:34 +00:00
< pre style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4" > < code > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 1
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 2
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 3
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 4
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 5
2019-01-10 18:35:05 +00:00
< / span > < / code > < / pre > < / td >
2019-12-11 13:32:34 +00:00
< td style = "vertical-align:top;padding:0;margin:0;border:0;;width:100%" >
2019-01-10 18:35:05 +00:00
< pre style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4" > < code class = "language-apache" data-lang = "apache" > < span style = "color:#f92672" > < Location< / span > < span style = "color:#e6db74" > /myapp/< / span > < span style = "color:#f92672" > > < / span >
ProxyPass http://127.0.0.1:8888/myapp/
ProxyPassReverse http://127.0.0.1:8888/myapp/
RequestHeader set SCRIPT_NAME < span style = "color:#e6db74" > " /myapp/" < / span >
2021-01-19 11:35:27 +00:00
< span style = "color:#f92672" > < /Location> < / span >
2019-12-11 13:32:34 +00:00
< / code > < / pre > < / td > < / tr > < / table >
2019-01-10 18:35:05 +00:00
< / div >
2019-12-11 13:32:34 +00:00
< / div > < p > < strong > Important< / strong > : < em > SCRIPT_NAME< / em > and the end of < em > ProxyPass< / em > URL < strong > MUST BE
2019-01-10 18:35:05 +00:00
THE SAME< / strong > . Otherwise, Gunicorn will fail miserably.< / p >
< p > Try it with:< / p >
< div class = "highlight" > < div style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4" >
< table style = "border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;" > < tr > < td style = "vertical-align:top;padding:0;margin:0;border:0;" >
2019-12-11 13:32:34 +00:00
< pre style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4" > < code > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 1
2019-01-10 18:35:05 +00:00
< / span > < / code > < / pre > < / td >
2019-12-11 13:32:34 +00:00
< td style = "vertical-align:top;padding:0;margin:0;border:0;;width:100%" >
< pre style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4" > < code class = "language-bash" data-lang = "bash" > venv/bin/gunicorn -w < span style = "color:#ae81ff" > 4< / span > -b 127.0.0.1:8888 --log-file - --access-logfile - wsgi:application
< / code > < / pre > < / td > < / tr > < / table >
2019-01-10 18:35:05 +00:00
< / div >
2019-12-11 13:32:34 +00:00
< / div > < h2 id = "uwsgi" > UWSGI< / h2 >
2019-01-10 18:35:05 +00:00
< p > This is a very simple configuration. I will try to upload one with more
options for uwsgi (in a .ini file).< / p >
< div class = "highlight" > < div style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4" >
< table style = "border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;" > < tr > < td style = "vertical-align:top;padding:0;margin:0;border:0;" >
2019-12-11 13:32:34 +00:00
< pre style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4" > < code > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 1
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 2
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 3
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 4
2019-01-10 18:35:05 +00:00
< / span > < / code > < / pre > < / td >
2019-12-11 13:32:34 +00:00
< td style = "vertical-align:top;padding:0;margin:0;border:0;;width:100%" >
2019-01-10 18:35:05 +00:00
< pre style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4" > < code class = "language-apache" data-lang = "apache" > < span style = "color:#f92672" > < Location< / span > < span style = "color:#e6db74" > /myapp/< / span > < span style = "color:#f92672" > > < / span >
SetHandler uwsgi_handler
uWSGISocker < span style = "color:#ae81ff" > 127.0.0.1< / span > :8888
2021-01-19 11:35:27 +00:00
< span style = "color:#f92672" > < /Location> < / span >
2019-12-11 13:32:34 +00:00
< / code > < / pre > < / td > < / tr > < / table >
2019-01-10 18:35:05 +00:00
< / div >
2019-12-11 13:32:34 +00:00
< / div > < p > Try it with:< / p >
2019-01-10 18:35:05 +00:00
< div class = "highlight" > < div style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4" >
< table style = "border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;" > < tr > < td style = "vertical-align:top;padding:0;margin:0;border:0;" >
2019-12-11 13:32:34 +00:00
< pre style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4" > < code > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 1
2019-01-10 18:35:05 +00:00
< / span > < / code > < / pre > < / td >
2019-12-11 13:32:34 +00:00
< td style = "vertical-align:top;padding:0;margin:0;border:0;;width:100%" >
< pre style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4" > < code class = "language-bash" data-lang = "bash" > uwsgi --socket 127.0.0.1:8888 -w wsgi:application
< / code > < / pre > < / td > < / tr > < / table >
2019-01-10 18:35:05 +00:00
< / div >
2019-12-11 13:32:34 +00:00
< / div > < h3 id = "extra-supervisor" > Extra: Supervisor< / h3 >
2019-01-10 18:35:05 +00:00
< p > If everything went as expected, you can wrap your command in a
supervisor config file and let it handle the server for you.< / p >
< div class = "highlight" > < div style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4" >
< table style = "border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;" > < tr > < td style = "vertical-align:top;padding:0;margin:0;border:0;" >
2019-12-11 13:32:34 +00:00
< pre style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4" > < code > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 1
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 2
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 3
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 4
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 5
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 6
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 7
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 8
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 9
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 10
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 11
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 12
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 13
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 14
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 15
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 16
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 17
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 18
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 19
2019-01-10 18:35:05 +00:00
< / span > < / code > < / pre > < / td >
2019-12-11 13:32:34 +00:00
< td style = "vertical-align:top;padding:0;margin:0;border:0;;width:100%" >
2019-01-10 18:35:05 +00:00
< pre style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4" > < code class = "language-ini" data-lang = "ini" > < span style = "color:#66d9ef" > [unix_http_server]< / span >
< span style = "color:#a6e22e" > file< / span > < span style = "color:#f92672" > =< / span > < span style = "color:#e6db74" > /tmp/myapp.sock ; path to your socket file< / span >
< span style = "color:#66d9ef" > [supervisord]< / span >
< span style = "color:#a6e22e" > logfile< / span > < span style = "color:#f92672" > =< / span > < span style = "color:#e6db74" > %(here)s/logs/supervisor.log< / span >
< span style = "color:#a6e22e" > childlogdir< / span > < span style = "color:#f92672" > =< / span > < span style = "color:#e6db74" > %(here)s/logs/< / span >
< span style = "color:#66d9ef" > [rpcinterface:supervisor]< / span >
< span style = "color:#a6e22e" > supervisor.rpcinterface_factory< / span > < span style = "color:#f92672" > =< / span > < span style = "color:#e6db74" > supervisor.rpcinterface:make_main_rpcinterface< / span >
< span style = "color:#66d9ef" > [supervisorctl]< / span >
< span style = "color:#a6e22e" > logfile< / span > < span style = "color:#f92672" > =< / span > < span style = "color:#e6db74" > %(here)s/logs/supervisorctl.log< / span >
< span style = "color:#a6e22e" > serverurl< / span > < span style = "color:#f92672" > =< / span > < span style = "color:#e6db74" > unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket< / span >
< span style = "color:#66d9ef" > [program:myapp]< / span >
< span style = "color:#a6e22e" > command< / span > < span style = "color:#f92672" > =< / span > < span style = "color:#e6db74" > venv/bin/gunicorn -w 4 -b 0.0.0.0:5000 --log-file %(here)s/logs/gunicorn.log --access-logfile - wsgi:application< / span >
< span style = "color:#a6e22e" > directory< / span > < span style = "color:#f92672" > =< / span > < span style = "color:#e6db74" > %(here)s< / span >
< span style = "color:#a6e22e" > environment< / span > < span style = "color:#f92672" > =< / span > < span style = "color:#e6db74" > PATH=%(here)s/venv/bin/< / span >
2019-12-11 13:32:34 +00:00
< span style = "color:#a6e22e" > logfile< / span > < span style = "color:#f92672" > =< / span > < span style = "color:#e6db74" > %(here)s/logs/myapp.log< / span >
< / code > < / pre > < / td > < / tr > < / table >
2019-01-10 18:35:05 +00:00
< / div >
< / div >
< / div >
< div id = "sidebar" class = "fixed" >
< div id = "badge" class = "flip-container" ontouchstart = "this.classList.toggle('hover');" >
2019-12-11 13:32:34 +00:00
< div class = "flipper sticky expand" >
2019-01-10 18:35:05 +00:00
< div class = "front" >
2019-12-11 13:32:34 +00:00
< img id = "avatar" class = "expandx" src = "../../img/me.png" >
2019-01-10 18:35:05 +00:00
< / div >
< div class = "back" >
2019-12-11 13:32:34 +00:00
< div id = "about" >
< div class = "icons vertical-center" >
< span class = "coolicon" > < span class = "fa-stack" > < i class = "fas fa-square fa-stack-2x" > < / i > < i class = "fab fa-inverse fa-stack-1x fa-linux" > < / i > < / span > < span class = "explanation" > Linux user< / span > < / span >
< span class = "coolicon" > < span class = "fa-stack" > < i class = "fas fa-square fa-stack-2x" > < / i > < i class = "fab fa-inverse fa-stack-1x fa-android" > < / i > < / span > < span class = "explanation" > Android dev and user< / span > < / span >
< a href = "http://github.com/balkian" target = "_blank" > < span class = "coolicon" > < span class = "fa-stack" > < i class = "fas fa-square fa-stack-2x" > < / i > < i class = "fab fa-inverse fa-stack-1x fa-github" > < / i > < / span > < span class = "explanation" > Github user< / span > < / span > < / a >
< a href = "http://gitlab.com/balkian" target = "_blank" > < span class = "coolicon" > < span class = "fa-stack" > < i class = "fas fa-square fa-stack-2x" > < / i > < i class = "fab fa-inverse fa-stack-1x fa-gitlab" > < / i > < / span > < span class = "explanation" > GitLab user< / span > < / span > < / a >
< span class = "coolicon" > < span class = "fa-stack" > < i class = "fas fa-square fa-stack-2x" > < / i > < i class = "fab fa-inverse fa-stack-1x fa-stack-exchange" > < / i > < / span > < span class = "explanation" > StackExchange fan< / span > < / span >
< span class = "coolicon" > < span class = "fa-stack" > < i class = "fas fa-square fa-stack-2x" > < / i > < i class = "fas fa-inverse fa-stack-1x fa-music" > < / i > < / span > < span class = "explanation" > Music lover< / span > < / span >
< span class = "coolicon" > < span class = "fa-stack" > < i class = "fas fa-square fa-stack-2x" > < / i > < i class = "fas fa-inverse fa-stack-1x fa-film" > < / i > < / span > < span class = "explanation" > Movie fan< / span > < / span >
< span class = "coolicon" > < span class = "fa-stack" > < i class = "fas fa-square fa-stack-2x" > < / i > < i class = "fas fa-inverse fa-stack-1x fa-laptop" > < / i > < / span > < span class = "explanation" > Always on a PC< / span > < / span >
< span class = "coolicon" > < span class = "fa-stack" > < i class = "fas fa-square fa-stack-2x" > < / i > < i class = "fas fa-inverse fa-stack-1x fa-moon" > < / i > < / span > < span class = "explanation" > Night owl< / span > < / span >
< span class = "coolicon" > < span class = "fa-stack" > < i class = "fas fa-square fa-stack-2x" > < / i > < i class = "fas fa-inverse fa-stack-1x fa-terminal" > < / i > < / span > < span class = "explanation" > CLI user< / span > < / span >
< span class = "coolicon" > < span class = "fa-stack" > < i class = "fas fa-square fa-stack-2x" > < / i > < i class = "fas fa-inverse fa-stack-1x fa-flag" > < / i > < / span > < span class = "explanation" > I love languages< / span > < / span >
< span class = "coolicon" > < span class = "fa-stack" > < i class = "fas fa-square fa-stack-2x" > < / i > < i class = "fas fa-inverse fa-stack-1x fa-code" > < / i > < / span > < span class = "explanation" > I love programming< / span > < / span >
< / div >
< / div >
2019-01-10 18:35:05 +00:00
< / div >
< / div >
< / div >
< div class = "entries" >
< h2 class = "title" > Latest entries< / h2 >
2019-12-11 13:32:34 +00:00
< dt > < a href = "../../post/2019-05-01-surface-go/" > Linux on the Microsoft Surface Go< / a > < / dt >
2019-01-10 18:35:05 +00:00
2019-12-11 13:32:34 +00:00
< a class = "tag" href = '../../tags/linux' > < span class = "label" > linux< / span > < / a >
2019-01-10 18:35:05 +00:00
2019-12-11 13:32:34 +00:00
< a class = "tag" href = '../../tags/surface-go' > < span class = "label" > surface go< / span > < / a >
2019-01-10 18:35:05 +00:00
2019-12-11 13:32:34 +00:00
< a class = "tag" href = '../../tags/config' > < span class = "label" > config< / span > < / a >
2019-01-10 18:35:05 +00:00
2019-12-11 13:32:34 +00:00
< dt > < a href = "../../post/2019-01-06-zigbee2mqtt/" > Controlling Zigbee devices with MQTT< / a > < / dt >
2019-01-10 18:35:05 +00:00
2019-12-11 13:32:34 +00:00
< a class = "tag" href = '../../tags/mqtt' > < span class = "label" > mqtt< / span > < / a >
2019-01-10 18:35:05 +00:00
2019-12-11 13:32:34 +00:00
< a class = "tag" href = '../../tags/iot' > < span class = "label" > iot< / span > < / a >
2019-01-10 18:35:05 +00:00
2019-12-11 13:32:34 +00:00
< a class = "tag" href = '../../tags/zigbee' > < span class = "label" > zigbee< / span > < / a >
2019-01-10 18:35:05 +00:00
2019-12-11 13:32:34 +00:00
< dt > < a href = "../../post/2016-09-28-tqdm/" > Progress bars in python< / a > < / dt >
2019-01-10 18:35:05 +00:00
2019-12-11 13:32:34 +00:00
< a class = "tag" href = '../../tags/python' > < span class = "label" > python< / span > < / a >
2019-01-10 18:35:05 +00:00
2019-12-11 13:33:45 +00:00
< dt > < a href = "../../post/2015-04-10-github-dotfiles/" > Sharing dotfiles< / a > < / dt >
< a class = "tag" href = '../../tags/github' > < span class = "label" > github < / span > < / a >
< a class = "tag" href = '../../tags/git' > < span class = "label" > git< / span > < / a >
< a class = "tag" href = '../../tags/dotfiles' > < span class = "label" > dotfiles< / span > < / a >
2019-01-10 18:35:05 +00:00
< / div >
< / div >
< div class = "clear" > < / div >
< / div >
< footer class = "pagefooter" role = "contentinfo" >
< div class = "contact" >
< p >
J. Fernando Sánchez Rada | balkian
< / p >
< / div >
< ul id = "social" >
< li > < a href = "http://github.com/balkian" > < i class = "fab fa-github" > < / i > < / a > < / li >
< li > < a href = "http://lab.gsi.upm.es/balkian" > < i class = "fab fa-gitlab" > < / i > < / a > < / li >
< li > < a href = "http://twitter.com/balkian" > < i class = "fab fa-twitter" > < / i > < / a > < / li >
< li > < a href = "http://git.sinpapel.es/balkian" > < i class = "fab fa-git" > < / i > < / a > < / li >
< li > < a href = "http://linkedin.com/in/jfsanchezrada" > < i class = "fab fa-linkedin" > < / i > < / a > < / li >
< / ul >
< p >
< i class = "fab fa-creative-commons" > < / i > Creative Commons A-SA-NC
< / p >
< / footer >
< / div >
< script src = "../../js/jquery-2.0.2.min.js" > < / script >
2019-01-11 14:45:46 +00:00
2019-01-10 18:35:05 +00:00
< / body >
< / html >