我有一台服务器,它当前将所有内容重定向到在同一台机器上的 Docker 容器中运行的 Web 应用程序。
我想将以 /mail 开头的 URL 定向到邮件捕手在另一个 Docker 容器中运行。
[这篇文章经过编辑,添加了我尝试过的新内容] 我到目前为止
ServerName myserver.uk
ServerAlias www.myserver.uk
ServerAdmin [email protected]
ProxyPreserveHost On
# My attempts to get MailCatcher working
# Rewrite rules are a complete mystery to me, I'm just taking these from one of the tutorials I have found
# Every tutorial seems to do it differently, which is confusing!
# Is websocket some magic keyword?
RewriteEngine on
RewriteCond ${HTTP:Upgrade} websocket [NC]
RewriteCond ${HTTP:Connection} upgrade [NC]
RewriteRule .* "wss:/localhost:1080/$1" [P,L]
ProxyPassMatch (.*)(\/websocket)$ "ws://127.0.0.1:1080/$1$2"
ProxyPass /assets/ http://localhost:1080/assets/
ProxyPassReverse /assets/ http://localhost:1080/assets/
ProxyPass /messages/ http://localhost:1080/messages/
ProxyPassReverse /messages/ http://localhost:1080/messages/
ProxyPass /mail/ http://localhost:1080/
ProxyPassReverse /mail/ http://localhost:1080/
# The main web app
ProxyPass / http://localhost:8090/
ProxyPassReverse / http://localhost:8090/
但我发现 mailcatcher 使用 Web Sockets。如果我通过浏览器运行控制台窗口,我会看到:
GET https://myserver.uk/messages 404 (Not Found)
mailcatcher.js:5 WebSocket connection to 'wss://myserver/messages' failed: Error during WebSocket handshake: Unexpected response code: 404
我显然遗漏了一些东西-我应该在我的 apache 配置中更改什么?
答案1
我最终放弃了,并创建了一个新域名来做 MailCatcher 的事情。我的配置文件最终如下:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName mc.myserver.uk
ServerAdmin [email protected]
ProxyPreserveHost On
ProxyRequests On
ProxyPass /messages/ ws://localhost:1080/messages/
ProxyPassReverse /messages/ http://localhost:1080/messages/
ProxyPass / http://localhost:1080/
ProxyPassReverse / http://localhost:1080/
RequestHeader set X-Forwarded-Proto "https"
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Location />
AuthType Basic
AuthName "Authentication Required"
AuthUserFile "/etc/htpasswd/.htpasswd"
Require valid-user
Order allow,deny
Allow from all
</Location>
SSLCertificateFile /etc/letsencrypt/live/mc.myserver.uk/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mc.myserver.uk/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
不幸的是,它只能在一定程度上起作用 - 它显示主屏幕和消息列表,但任何显示消息的尝试都会失败并出现 500 服务器错误。