【问题标题】:Apache proxypass redirect to multiple unix socketsApache proxypass 重定向到多个 unix 套接字
【发布时间】:2020-01-10 22:45:23
【问题描述】:

我有一个使用 gunicorn.socket 运行多个烧瓶实例的服务器,并且配置了一个 apache2 服务器来代理请求:

<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>

如上所示,如果我只启用site0,一切正常,即当我在浏览器中输入 127.0.1.1/ 时,它会代理到 url 为 127.0.1.1/ 的gunicorn_site0.sock

但是,我真正想做的是允许以下操作:

# 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

我用 RewriteRule 尝试了多种方法,但没有成功。

有什么想法吗?

【问题讨论】:

    标签: server apache2 reverse-proxy gunicorn


    【解决方案1】:

    您是否尝试在 /0 中使用“第一个站点”而不是 / ?没有理由失败,但我认为你首先 proxypass “吃”了所有子网址:

    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
    

    但是,您可能需要确保所有 python 应用程序都可以在“子目录”中运行。 (例如通过在 gunicorn env 中设置 SCRIPT_NAME)

    【讨论】:

      猜你喜欢
      • 2016-07-31
      • 2017-02-04
      • 2011-01-10
      • 1970-01-01
      • 2018-03-25
      • 2014-05-25
      • 1970-01-01
      • 1970-01-01
      • 2018-02-05
      相关资源
      最近更新 更多