mirror of
https://github.com/balkian/balkian.github.com.git
synced 2024-12-26 10:18:13 +00:00
246 lines
13 KiB
HTML
246 lines
13 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
|
<title>balkian.com - Proxies with Apache and python
|
|
</title>
|
|
<meta name="viewport" content="width=device-width">
|
|
|
|
<!-- syntax highlighting CSS -->
|
|
<link rel="stylesheet" href="/theme/css/solarized.css">
|
|
<!--<link href="/css/bootstrap.css" rel="stylesheet">-->
|
|
<link rel="stylesheet" href="/theme/font-awesome/css/font-awesome.min.css">
|
|
|
|
<!--<link rel="stylesheet" href="/css/bootstrap-responsive.min.css">-->
|
|
|
|
<!-- Custom CSS -->
|
|
<link rel="stylesheet" media="only screen" href="/theme/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>
|
|
<a href="/category/cheats.html"><li >
|
|
Cheats
|
|
</li></a>
|
|
<a href="/category/misc.html"><li class="active"
|
|
>
|
|
Misc
|
|
</li></a>
|
|
<a href="/tags.html"><li >
|
|
Tags
|
|
</li></a>
|
|
<a href="/pages/projects.html"><li >
|
|
Projects
|
|
</li></a>
|
|
<a href="//jfernando.es" target="_blank"><li>
|
|
CV
|
|
</li></a>
|
|
</ul>
|
|
</header>
|
|
<!--Body content-->
|
|
<div class="postnav">
|
|
<span class="previouspost"><i class="fa fa-chevron-left"></i> <a href="publishing-on-pypi.html">Publishing on PyPi</a></span>
|
|
<span class='nextpost'><a href="/zotero.html">Zotero</a> <i class="fa fa-chevron-right"></i></span>
|
|
</div>
|
|
<div class="posthead">
|
|
<h2 class="title">Proxies with Apache and python</h2>
|
|
<span class="meta date">2014-10-09</span>
|
|
<span class="tag"><a href="/tag/python.html" class="label label-default">python</a></span>
|
|
<span class="tag"><a href="/tag/apache.html" class="label label-default">apache</a></span>
|
|
<span class="tag"><a href="/tag/proxy.html" class="label label-default">proxy</a></span>
|
|
<span class="tag"><a href="/tag/gunicorn.html" class="label label-default">gunicorn</a></span>
|
|
<span class="tag"><a href="/tag/uwsgi.html" class="label label-default">uwsgi</a></span>
|
|
</div>
|
|
|
|
<div class="post">
|
|
<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>
|
|
<div class="section" id="gunicorn">
|
|
<h2>Gunicorn</h2>
|
|
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
|
2
|
|
3
|
|
4
|
|
5</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="nt"><Location</span> <span class="s">/myapp/</span><span class="nt">></span>
|
|
<span class="nb">ProxyPass</span> http://127.0.0.1:8888/myapp/
|
|
<span class="nb">ProxyPassReverse</span> http://127.0.0.1:8888/myapp/
|
|
<span class="nb">RequestHeader</span> set SCRIPT_NAME <span class="s2">"/myapp/"</span>
|
|
<span class="nt"></Location></span>
|
|
</pre></div>
|
|
</td></tr></table><p><strong>Important</strong>: <em>SCRIPT_NAME</em> and the end of <em>ProxyPass</em> URL <strong>MUST BE
|
|
THE SAME</strong>. Otherwise, Gunicorn will fail miserably.</p>
|
|
<p>Try it with:</p>
|
|
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre><span></span>venv/bin/gunicorn -w <span class="m">4</span> -b <span class="m">127</span>.0.0.1:8888 --log-file - --access-logfile - wsgi:application
|
|
</pre></div>
|
|
</td></tr></table></div>
|
|
<div class="section" id="uwsgi">
|
|
<h2>UWSGI</h2>
|
|
<p>This is a very simple configuration. I will try to upload one with more
|
|
options for uwsgi (in a .ini file).</p>
|
|
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
|
2
|
|
3
|
|
4</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="nt"><Location</span> <span class="s">/myapp/</span><span class="nt">></span>
|
|
<span class="nb">SetHandler</span> uwsgi_handler
|
|
<span class="nb">uWSGISocker</span> <span class="m">127.0.0.1</span>:8888
|
|
<span class="nt"></Location></span>
|
|
</pre></div>
|
|
</td></tr></table><p>Try it with:</p>
|
|
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre><span></span>uwsgi --socket <span class="m">127</span>.0.0.1:8888 -w wsgi:application
|
|
</pre></div>
|
|
</td></tr></table><div class="section" id="extra-supervisor">
|
|
<h3>Extra: Supervisor</h3>
|
|
<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>
|
|
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
|
8
|
|
9
|
|
10
|
|
11
|
|
12
|
|
13
|
|
14
|
|
15
|
|
16
|
|
17
|
|
18
|
|
19</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">[unix_http_server]</span>
|
|
<span class="na">file</span><span class="o">=</span><span class="s">/tmp/myapp.sock ; path to your socket file</span>
|
|
|
|
<span class="k">[supervisord]</span>
|
|
<span class="na">logfile</span> <span class="o">=</span> <span class="s">%(here)s/logs/supervisor.log</span>
|
|
<span class="na">childlogdir</span> <span class="o">=</span> <span class="s">%(here)s/logs/</span>
|
|
|
|
<span class="k">[rpcinterface:supervisor]</span>
|
|
<span class="na">supervisor.rpcinterface_factory</span> <span class="o">=</span> <span class="s">supervisor.rpcinterface:make_main_rpcinterface</span>
|
|
|
|
<span class="k">[supervisorctl]</span>
|
|
<span class="na">logfile</span> <span class="o">=</span> <span class="s">%(here)s/logs/supervisorctl.log</span>
|
|
<span class="na">serverurl</span><span class="o">=</span><span class="s">unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket</span>
|
|
|
|
<span class="k">[program:myapp]</span>
|
|
<span class="na">command</span> <span class="o">=</span> <span class="s">venv/bin/gunicorn -w 4 -b 0.0.0.0:5000 --log-file %(here)s/logs/gunicorn.log --access-logfile - wsgi:application</span>
|
|
<span class="na">directory</span> <span class="o">=</span> <span class="s">%(here)s</span>
|
|
<span class="na">environment</span> <span class="o">=</span> <span class="s">PATH=%(here)s/venv/bin/</span>
|
|
<span class="na">logfile</span> <span class="o">=</span> <span class="s">%(here)s/logs/myapp.log</span>
|
|
</pre></div>
|
|
</td></tr></table></div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<div id="sidebar" >
|
|
<div id="badge" class="flip-container" ontouchstart="this.classList.toggle('hover');">
|
|
<div class="flipper sticky">
|
|
<div class="front">
|
|
<!-- front content -->
|
|
<img id="avatar" src="/theme/img/me.png">
|
|
</div>
|
|
<div class="back">
|
|
<!-- back content -->
|
|
<img id="picture" src="/theme/img/me-bat.png">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="entries">
|
|
<h2 class="title">Latest entries</h2>
|
|
<dl>
|
|
<dt><a href="/controlling-zigbee-devices-with-mqtt.html">Controlling Zigbee devices with MQTT</a></dt>
|
|
<dd class="tag"><a class="label" href="/tag/mqtt.html">mqtt</a></dd>
|
|
<dd class="tag"><a class="label" href="/tag/iot.html">iot</a></dd>
|
|
<dd class="tag"><a class="label" href="/tag/zigbee.html">zigbee</a></dd>
|
|
<dt><a href="/hdmi-vga-adapter-issues-with-raspberry-pi.html">HDMI-VGA adapter issues with Raspberry Pi</a></dt>
|
|
<dd class="tag"><a class="label" href="/tag/rpi.html">rpi</a></dd>
|
|
<dt><a href="/pptp-connections.html">PPTP connections</a></dt>
|
|
<dd class="tag"><a class="label" href="/tag/openwrt.html">openwrt</a></dd>
|
|
<dd class="tag"><a class="label" href="/tag/linux.html">linux</a></dd>
|
|
<dd class="tag"><a class="label" href="/tag/router.html">router</a></dd>
|
|
<dt><a href="/progress-bars-in-python.html">Progress bars in python</a></dt>
|
|
<dd class="tag"><a class="label" href="/tag/python.html">python</a></dd>
|
|
<dt><a href="/arch-linux-fixes.html">Arch Linux Fixes</a></dt>
|
|
<dd class="tag"><a class="label" href="/tag/arch.html">arch</a></dd>
|
|
<dd class="tag"><a class="label" href="/tag/linux.html">linux</a></dd>
|
|
</dl>
|
|
</div>
|
|
<div class="about" style="clear:both;">
|
|
<!-- <h2 class="title">About me</h2> -->
|
|
<div class="icons">
|
|
<span class="coolicon"><span class="fa fa-stack"> <i class="fa fa-square-o fa-stack-2x" ></i><i class="fa fa-stack-1x fa-linux"></i></span><span class="explanation">Linux lover</span></span>
|
|
<span class="coolicon"><span class="fa fa-stack"> <i class="fa fa-square-o fa fa-stack-2x" ></i><i class="fa fa-android"></i></span><span class="explanation">Android dev</span></span>
|
|
<span class="coolicon"><span class="fa fa-stack"> <i class="fa fa-square-o fa fa-stack-2x" ></i><i class="fa fa-github-alt"></i> </span><span class="explanation">GitHub user</span></span>
|
|
<span class="coolicon"><span class="fa fa-stack"> <i class="fa fa-square-o fa fa-stack-2x" ></i><i class="fa fa-stack-exchange"></i> </span><span class="explanation">StackExchange fan</span></span>
|
|
<span class="coolicon"><span class="fa fa-stack"> <i class="fa fa-square-o fa fa-stack-2x" ></i><i class="fa fa-music"></i> </span><span class="explanation">Music lover</span></span>
|
|
<span class="coolicon"><span class="fa fa-stack"> <i class="fa fa-square-o fa fa-stack-2x" ></i><i class="fa fa-film"></i> </span><span class="explanation">Movie fan</span></span>
|
|
<span class="coolicon"><span class="fa fa-stack"> <i class="fa fa-square-o fa fa-stack-2x" ></i><i class="fa fa-comments"></i> </span><span class="explanation">Always on IM</span></span>
|
|
<span class="coolicon"><span class="fa fa-stack"> <i class="fa fa-square-o fa fa-stack-2x" ></i><i class="fa fa-laptop"></i> </span><span class="explanation">Always on a PC</span></span>
|
|
<span class="coolicon"><span class="fa fa-stack"> <i class="fa fa-square-o fa fa-stack-2x" ></i><i class="fa fa-pencil"></i> </span><span class="explanation">Occassional writter</span></span>
|
|
<span class="coolicon"><span class="fa fa-stack"> <i class="fa fa-square-o fa fa-stack-2x" ></i><i class="fa fa-moon-o"></i> </span><span class="explanation">Night owl</span></span>
|
|
<span class="coolicon"><span class="fa fa-stack"> <i class="fa fa-square-o fa fa-stack-2x" ></i><i class="fa fa-terminal"></i></span> <span class="explanation">CLI user</span></span>
|
|
<span class="coolicon"><span class="fa fa-stack"> <i class="fa fa-square-o fa fa-stack-2x" ></i><i class="fa fa-flag"></i></span> <span class="explanation">Linguist wannabe</span></span>
|
|
<span class="coolicon"><span class="fa fa-stack"> <i class="fa fa-square-o fa fa-stack-2x" ></i><i class="fa fa-code"></i> </span> <span class="explanation">Love to code</span></span>
|
|
<span class="coolicon"><span class="fa fa-stack"> <i class="fa fa-square-o fa fa-stack-2x" ></i><i class="fa fa-book"></i></span> <span class="explanation">Keen reader</span></span>
|
|
<span class="coolicon"><span class="fa fa-stack"> <i class="fa fa-square-o fa fa-stack-2x" ></i><i class="fa fa-quote-right"></i></span> <span class="explanation">Quotes on demand</span></span>
|
|
</div>
|
|
</div>
|
|
|
|
<!--Sidebar content-->
|
|
</div> <div class="clear"></div>
|
|
</div>
|
|
<footer 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="fa fa-github"></i></a></li>
|
|
<li><a href="http://bitbucket.com/balkian"><i class="fa fa-bitbucket"></i></a></li>
|
|
<li><a href="http://twitter.com/balkian"><i class="fa fa-twitter"></i></a></li>
|
|
<li><a href="https://plus.google.com/u/0/111897020957944410316"><i class="fa fa-google-plus"></i></a></li>
|
|
<li><a href="http://linkedin.com/in/jfsanchezrada"><i class="fa fa-linkedin"></i></a></li>
|
|
<li><a href="http://facebook.com/balkian"><i class="fa fa-facebook"></i></a></li>
|
|
</ul>
|
|
<p>
|
|
<i class="fa fa-creative-commons"></i> Creative Commons A-SA-NC
|
|
</p>
|
|
</footer>
|
|
</div>
|
|
|
|
<script src="/theme/js/jquery-2.0.2.min.js"></script>
|
|
<!-- Piwik -->
|
|
<script type="text/javascript">
|
|
var _paq = _paq || [];
|
|
_paq.push(['trackPageView']);
|
|
_paq.push(['enableLinkTracking']);
|
|
(function() {
|
|
var u="//piwik.sinpapel.es/";
|
|
_paq.push(['setTrackerUrl', u+'piwik.php']);
|
|
_paq.push(['setSiteId', 2]);
|
|
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
|
|
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
|
|
})();
|
|
</script>
|
|
<noscript><p><img src="//piwik.sinpapel.es/piwik.php?idsite=2" style="border:0;" alt="" /></p></noscript>
|
|
<!-- End Piwik Code -->
|
|
|
|
<!--<script src="/js/bootstrap.min.js"></script>-->
|
|
</body>
|
|
</html> |