我想设置一个 Apache 服务器,以便它将请求
https://example.edu/rdemos/(.*)
重定向到在端口 3838 上运行的闪亮服务器。其他网页应该转到普通的代理服务器。
所以我的
ssl.conf
中有以下指令:
RewriteEngine on
RewriteRule ^/PP/(.*) https://example.com/PhysicsPlayground/$1
<Location /rdemos>
RedirectMatch permanent ^/rdemos$ /rdemos/
RewriteEngine on
RewriteCond %{HTTP:Upgrade} =websocket
RewriteRule /rdemos/(.*) ws://localhost:3838/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket
RewriteRule /rdemos/(.*) http://localhost:3838/$1 [P,L]
ProxyPass http://localhost:3838/
ProxyPassReverse http://localhost:3838/
# Header edit Location ^/ /rdemos/
</Location>
这会正确重定向
/rdemos
下的文件,因此 https://example.com/rdemos/index.html
按预期转到闪亮服务器(端口 3838)。
但是,其他文件会随机重定向。因此
https://example.com/PP/demo.html
被路由到 https://example.com/rdemos/PhysicsPlayground/demo.html
(不存在)。
我做错了什么?
我正在使用 Apache/2.4.37(红帽企业 Linux)OpenSSL/1.1.1k mod_fcgid/2.3.9 SVN/1.10.2 mod_wsgi/4.6.4 Python/3.6 mod_apreq2-20101207/2.8.1
我不会尝试混合 mod_alias 和 mod_rewrite 指令。将所有内容转换为 mod_rewrite 因为您需要使用它。
重定向重写规则应使用
[R=301,L]
我不会尝试将
ProxyPass
与带有 P
标志的重写规则混合在一起。只需使用重写规则即可。
在重写规则中使用
^/?
更便于移植,这样它们就可以在.htaccess
中工作而无需修改。
您无需多次指定
RewriteEngine on
。
ProxyPassReverse
应指定子目录。
RewriteEngine on
RewriteRule ^/?PP/(.*) https://example.com/PhysicsPlayground/$1 [R=301,L]
RewriteRule ^/?rdemos$ /rdemos/ [R=301,L]
RewriteCond %{HTTP:Upgrade} =websocket
RewriteRule ^/?rdemos/(.*) ws://localhost:3838/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket
RewriteRule ^/?rdemos/(.*) http://localhost:3838/$1 [P,L]
ProxyPassReverse /rdemos/ http://localhost:3838/