我是 proxypass 的新手,假设这是我们的配置:
<IfModule mod_ssl.c>
<VirtualHost *:443>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
ServerName www.xzos.net
Include /etc/letsencrypt/options-ssl-apache.conf
ServerAlias xzos.net
SSLCertificateFile /etc/letsencrypt/live/www.xzos.net/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.xzos.net/privkey.pem
<LocationMatch "/ray/">
ProxyPass ws://127.0.0.1:1080/ray/ upgrade=WebSocket
ProxyAddHeaders Off
ProxyPreserveHost On
RequestHeader set Host %{HTTP_HOST}s
RequestHeader set X-Forwarded-For %{REMOTE_ADDR}s
</LocationMatch>
</VirtualHost>
</IfModule
由于我们向 Apache 提供了这些
SSLCertificateFile /etc/letsencrypt/live/www.xzos.net/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.xzos.net/privkey.pem
我们也不需要在运行的 websocket 服务器上使用它们ws://127.0.0.1:1080/ray/
,对吗?
尽管我们可以这样做,但 apache 可以处理它,对吧?而且我猜,由于这是本地服务器,所以两次执行是多余的。我认为如果我们这样做,那么就ws://127.0.0.1:1080/ray/
需要成为wss://127.0.0.1:1080/ray/
并在该 websocket 服务器内部提供相同的证书密钥。
答案1
使用 proxyPass 代理到 localhost 上不安全的侦听器仍然会暴露攻击面。您是否担心有人嗅探 localhost 上的流量?如果我是一个拥有适当访问权限的恶意人员,我可以在端口 1080 上的环回接口上执行 tcpdump 并读取流量。如果您使用 wss://,那么这样做会更加困难。我会在两个链接上使用 TLS,除非有技术原因,或者我正在调试应用程序并需要在此过程中获取更多信息。
答案2
我可以发表我的意见。
让我们关注<LocationMatch "/ray/">
。如果路径封装在 TLS 加密通道中,Apache 应该如何识别路径/ray/
?当然,Apache 必须处理 TLS 才能解密 http 握手并查看GET /whatever/
,然后确定它是否与位置匹配。