Reputation: 521
I have a server that runs multiple flask instances using gunicorn.socket, and an apache2 server is configured to proxy the request:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / unix:///run/gunicorn_site0.sock|http://127.0.1.1/
ProxyPassReverse / unix:///run/gunicorn_site0.sock|http://127.0.1.1/
# RewriteEngine On
# RewriteRule ^/0/(.*)$ unix:///run/gunicorn_site0.sock|http://127.0.1.1/$1 [P,L]
# ProxyPass /1 unix:///run/gunicorn_site1.sock|http://127.0.1.1/
# ProxyPassReverse /1 unix:///run/gunicorn_site1.sock|http://127.0.1.1/
# ProxyPass /2 unix:///run/gunicorn_site2.sock|http://127.0.1.1/
# ProxyPassReverse /2 unix:///run/gunicorn_site2.sock|http://127.0.1.1/
</VirtualHost>
As shown above, if I only enable site0
, everything works fine, i.e., when I type 127.0.1.1/ in the browser, it proxies to gunicorn_site0.sock
with url 127.0.1.1/
However, what I really want to do is to allow the follows:
# Typed in address bar Actual request
http://127.0.1.1/0/some/path -> gunicorn_site0.sock 127.0.1.1/some/path
http://127.0.1.1/1/some/path -> gunicorn_site1.sock 127.0.1.1/some/path
http://127.0.1.1/2/some/path -> gunicorn_site2.sock 127.0.1.1/some/path
I tried multiple ways with RewriteRule but with no success.
Any ideas?
Upvotes: 1
Views: 1900
Reputation: 443
Did you try with a "first site" in /0 instead of / ? there is no reason it fail, but i think you first proxypass "eat" all sub urls:
ProxyPass /0 unix:///run/gunicorn_site0.sock|http://127.0.1.1/0
ProxyPass /1 unix:///run/gunicorn_site1.sock|http://127.0.1.1/1
ProxyPass /2 unix:///run/gunicorn_site2.sock|http://127.0.1.1/2
However you will probably need to make sure all python app are ok running in a "sub-directory". (eg by setting SCRIPT_NAME in gunicorn env)
Upvotes: 1