【发布时间】:2020-01-06 19:02:19
【问题描述】:
我正在尝试将 Apache 配置为我们的 websoket 服务器 http://localhost:8000 的加密代理 https://chat.example.com(在同一操作系统上)。我根据官方文档启用了 mod_proxy、mod_proxy_http、mod_proxy_wstunnel、mod_rewrite 和 mod_ssl。
然后我向https://chat.example.com/connection/info?t=123144343 发出了一个常规的 https GET 请求,但 Apache 将其重写为http://localhost:8000/?t=123144343 而不是http://localhost:8000/connection/info?t=123144343。为什么?
<VirtualHost *:443>
ServerAdmin admin@example.com
ServerName chat.example.com
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule ^(.*)$ ws://localhost:8000/ [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule ^(.*)$ http://localhost:8000/ [P,L]
ProxyRequests Off
ProxyPreserveHost On
SSLEngine on
SSLProtocol +TLSv1 +TLSv1.1 +TLSv1.2 +TLSv1.3
SSLCertificateFile /etc/ssl/certs/example.com.crt
SSLCertificateKeyFile /etc/ssl/private/example.com.key
SSLCertificateChainFile /etc/ssl/certs/example.com-chain.crt
LogLevel rewrite:trace7
ErrorLog /var/log/example.com/chat_error.log
CustomLog /var/log/example.com/chat_access.log io
</VirtualHost>
[Wed Dec 25 18:57:16.057448 2019] [rewrite:trace2] [pid 9604:tid 140105269184256] mod_rewrite.c(483): init rewrite engine with requested uri /connection/info, referer: https://example.com/personal/chats
[Wed Dec 25 18:57:16.057523 2019] [rewrite:trace3] [pid 9604:tid 140105269184256] mod_rewrite.c(483): applying pattern '^(.*)$' to uri '/connection/info', referer: https://example.com/personal/chats
[Wed Dec 25 18:57:16.057566 2019] [rewrite:trace4] [pid 9604:tid 140105269184256] mod_rewrite.c(483): RewriteCond: input='' pattern='=websocket' [NC] => not-matched, referer: https://example.com/personal/chats
[Wed Dec 25 18:57:16.057600 2019] [rewrite:trace3] [pid 9604:tid 140105269184256] mod_rewrite.c(483): applying pattern '^(.*)$' to uri '/connection/info', referer: https://example.com/personal/chats
[Wed Dec 25 18:57:16.057637 2019] [rewrite:trace4] [pid 9604:tid 140105269184256] mod_rewrite.c(483): RewriteCond: input='' pattern='!=websocket' [NC] => matched, referer: https://example.com/personal/chats
[Wed Dec 25 18:57:16.057670 2019] [rewrite:trace2] [pid 9604:tid 140105269184256] mod_rewrite.c(483): rewrite '/connection/info' -> 'http://localhost:8000/', referer: https://example.com/personal/chats
[Wed Dec 25 18:57:16.057702 2019] [rewrite:trace2] [pid 9604:tid 140105269184256] mod_rewrite.c(483): forcing proxy-throughput with http://localhost:8000/, referer: https://example.com/personal/chats
[Wed Dec 25 18:57:16.057735 2019] [rewrite:trace1] [pid 9604:tid 140105269184256] mod_rewrite.c(483): go-ahead with proxy request proxy:http://localhost:8000/ [OK], referer: https://example.com/personal/chats
【问题讨论】:
-
“我向
http://chat.example.com/connection/info?t=123144343发出了一个常规的http GET 请求” - 那是HTTP(端口80),而不是HTTPS(端口443)?或者这只是你问题中的一个错字? -
对不起,这只是一个错字。固定
标签: mod-rewrite apache2