![使用 Uwsgi 与 Apache 2.4.51 和 Flask App 进行 Unix 套接字通信并返回“404 Not Found”](https://linux22.com/image/772416/%E4%BD%BF%E7%94%A8%20Uwsgi%20%E4%B8%8E%20Apache%202.4.51%20%E5%92%8C%20Flask%20App%20%E8%BF%9B%E8%A1%8C%20Unix%20%E5%A5%97%E6%8E%A5%E5%AD%97%E9%80%9A%E4%BF%A1%E5%B9%B6%E8%BF%94%E5%9B%9E%E2%80%9C404%20Not%20Found%E2%80%9D.png)
我在前端使用 Apache 作为 Web 服务器,在后端运行 python flask 应用程序,它们使用 Unix 套接字进行通信,如下面的 mod_proxy_uwsgi 模块链接中所述,并且我已按照建议加载了 mod_proxy 和 mod_proxy_uwsgi https://uwsgi-docs.readthedocs.io/en/latest/Apache.html
httpd/bin/apachectl -S
VirtualHost configuration:
*:2020 host-rh7-1 (/home/user/httpd-2.4.51/conf/httpd.conf:156)
*:2022 host-rh7-1 (/home/user/httpd-2.4.51/conf/httpd.conf:169)
*:2021 host-rh7-1 (/home/user/httpd-2.4.51/conf/extra/httpd-ssl.conf:123)
*:2023 host-rh7-1 (/home/user/httpd-2.4.51/conf/extra/httpd-ssl.conf:294)
ServerRoot: "/home/user/httpd-2.4.51"
Main DocumentRoot: "/home/user/web/html"
Main ErrorLog: "/home/user/httpd-2.4.51/logs/error_log"
Mutex default: dir="/home/user/httpd-2.4.51/logs/" mechanism=default
Mutex proxy-balancer-shm: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex ssl-cache: using_defaults
PidFile: "/home/user/httpd-2.4.51/logs/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="user" id=995 not_used
Group: name="support" id=1034 not_used
-------------------------------------
httpd.conf
------------
<VirtualHost *:2022>
ProxyPass / unix:/home/user/flask_app/myproject.sock|uwsgi://home/user/flask_app/
</VirtualHost>
uwsgi conf.ini
---------------
[uwsgi]
chdir = /home/user/flask_app
module = app
master = true
processes = 2
thread = 2
socket = myproject.sock
chmod-socket = 660
enable-threads = true
vacuum = true
die-on-term = true
在我运行 Apache 2.4.48 之前它都运行正常,但是将 Apache 升级到 2.4.51 之后,它停止工作了,我看不到 http 请求到达 flask 应用程序,而是显示“404 Not Found”。
我知道有一个与此相关的漏洞单,其指出“CVE-2021-40438 是 Apache HTTP Server 版本 2.4.48 及更早版本中的服务器端请求伪造 (SSRF) 漏洞”,并且 Apache 已在 2.4.51 中修复了该漏洞问题,但我不了解该修复在我的配置中的全部效果。
更多信息请点击此链接 https://www.fastly.com/blog/apache-redux-preventing-server-side-request-forgery-via-cve-2021-40438 并且修复似乎在本次修订中 https://svn.apache.org/viewvc?view=revision&revision=1892814
是否有其他方法可以在 httpd.conf 中启用 Unix 套接字通信,或者我必须改用 TCP 套接字?
请注意,我知道如果我使用 TCP 套接字而不是 Unix 套接字,如下所示,它可以正常工作
httpd.conf
-----------
<VirtualHost *:2022>
ProxyPass / uwsgi://127.0.0.1:2024/
</VirtualHost>
uwsgi conf.ini
--------------
[uwsgi]
chdir = /home/user/flask_app
module = app
master = true
processes = 2
thread = 2
socket = 127.0.0.1:2024
enable-threads = true
vacuum = true
die-on-term = true
答案1
在看到了更多示例之后,我尝试了另一种版本的 ProxyPass 行编码,如下所示,并且它对我有用:
httpd.conf
------------
<VirtualHost *:2022>
ProxyPass / unix:/home/user/flask_app/myproject.sock|uwsgi://localhost/
</VirtualHost>