【问题标题】:Apache mod_proxy_uwsgi and unix domain socketsApache mod_proxy_uwsgi 和 unix 域套接字
【发布时间】:2014-01-09 12:03:38
【问题描述】:

我有一个为 unix 域套接字运行的 uwsgi 服务器

[uwsgi]
...
socket = /var/run/someuwsgi.sock
socket = localhost:9987
...

mod_proxy_uwsgi 已安装

在 apache config 中有那一行: ProxyPass /some uwsgi://localhost:9987

它正在工作。

问题:通过 unix 域套接字的 apache 配置行应该是什么 /var/run/someuwsgi.sock ? 我试过了

ProxyPass /some uwsgi:///var/run/someuwsgi.sock

得到了

Bad Request
Your browser sent a request that this server could not understand.

也试过了

ProxyPass /some uwsgi://unix:///var/run/someuwsgi.sock

得到了

Proxy Error

The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /some/.

Reason: DNS lookup failure for: unix:

谢谢!

【问题讨论】:

    标签: apache config uwsgi unix-socket


    【解决方案1】:

    Starting from Apache 2.4.7,已添加对 Unix 套接字的支持。语法很简单:

    ProxyPass / unix:/tmp/uwsgi.sock|uwsgi://
    

    【讨论】:

    • 我不得不把localhost/放在最后。也许是因为我要去一个子目录 ProxyPass /e_app/ unix:/var/run/uwsgi/app/app1/socket|uwsgi://localhost/
    • #metoo 。 . .需要的格式为:ProxyPass / unix:/a/b/c/d/uwsgi.sock|uwsgi://localhost/
    【解决方案2】:

    不幸的是,apache 代理 api(当前)不支持 unix 套接字

    【讨论】:

      【解决方案3】:

      从另一个答案的 cmets 和我的经验来看,这似乎是正确的语法:

      ProxyPass /some unix:/var/run/someuwsgi.sock|uwsgi://localhost
      

      https://httpd.apache.org/docs/trunk/en/mod/mod_proxy.html#proxypass

      在 2.4.7 及更高版本中,可以通过使用前缀为 unix:/path/lis.sock| 的目标来支持使用 Unix 域套接字。例如,要代理 HTTP 并将 UDS 定位在 /home/www.socket,您将使用 unix:/home/www.socket|http://localhost/whatever/。由于套接字是本地的,因此使用的主机名(在本例中为 localhost)没有实际意义,但它作为请求的 Host: 标头值传递。

      【讨论】:

        猜你喜欢
        • 2010-11-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-02
        • 1970-01-01
        • 2015-07-20
        • 2014-07-18
        • 1970-01-01
        相关资源
        最近更新 更多