休息室给出了使用 Apache 反向代理的示例。
RewriteEngine On
RewriteRule ^/irc$ /irc/ [R]
RewriteCond %{REQUEST_URI} ^/irc/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /irc/(.*) ws://127.0.0.1:9000/$1 [P,L]
RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
ProxyVia On
ProxyRequests Off
ProxyAddHeaders On
ProxyPass /irc/ http://127.0.0.1:9000/
ProxyPassReverse /irc/ http://127.0.0.1:9000/
# By default Apache times out connections after one minute
ProxyTimeout 86400 # 1 day
它使用子文件夹,但我更愿意使用子域名。比如…
https://irc.domain.tld
代替…
https://domain.tld/irc/
对于只想为朋友设置一项好服务的人来说,正则表达式非常复杂……经过这么多次失败的尝试,我真的需要一些帮助!拜托,拜托?
感谢阅读<3
答案1
这与 The Lounge 或反向代理无关,而是 Apache 如何处理虚拟主机官方文档甚至提供了常见设置的示例,包括Virtual_host
与 mod_proxy 一起使用。
<VirtualHost *:443>
ServerName irc.example.com
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://127.0.0.1:9000/$1 [P,L]
RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
ProxyVia On
ProxyRequests Off
ProxyAddHeaders On
ProxyPass / http://127.0.0.1:9000/
ProxyPassReverse / http://127.0.0.1:9000/
# By default Apache times out connections after one minute
ProxyTimeout 86400 # 1 day
</VirtualHost>
mod_rewrite 仅用于允许 HTTP 和 Websocket 连接。如果您只需要 Websocket,则其配置会变得容易得多,如修改代理服务器:
<VirtualHost *:443>
ServerName irc.example.com
ProxyPass / ws://127.0.0.1:9000/
</VirtualHost>