我有一台在 Ubuntu 上运行的服务器。我可以使用 Apache 通过反向代理访问该服务器。现在开始我想要做的事情。当请求以下 uri 时,我想重定向到另一台服务器(不是同一台机器):
- /osimis-viewer/app/index.html?study={ID}
- /osimis-viewer/app/index.html?series={ID}
- /web-viewer/app/viewer.html?series={ID}
Uri 必须相同,因此如果我请求,localhost/osimis-viewer/app/index.html?study={ID}
我应该被重定向到new-ip/osimis-viewer/app/index.html?study={ID}
我正在尝试通过 mod_rewrite 来实现,但我无法让它工作。如果能得到
一些帮助,我将不胜感激。
sites-enabled 中的配置文件如下所示:
<VirtualHost *:80>
ProcyRequests Off
ProxyPass "/" "http://localhost:8042/"
ProxyPassReverse "/" "http://localhost:8042/"
ErrorLog /var/log/apache2/orthanc-error.log
CustomLog /var/log/apache2/orthanc-access.log combined
LogLevel error
// Some tries with RewriteRule
</VirtualHost>
答案1
问题可能是您在更具包容性的ProxyPass "/"
指令之后附加了额外的反向代理设置,因此它们永远不适用。ProxyPass
规则按配置顺序进行检查。第一个匹配的规则获胜,因此请尝试:
尝试:
<VirtualHost *:80>
ProxyRequests Off
ProxyPass "/osimis-viewer/app/index.html" "http://new-ip/osimis-viewer/app/index.html"
ProxyPassReverse "/osimis-viewer/app/index.html" "http://new-ip/osimis-viewer/app/index.html"
ProxyPass "/" "http://localhost:8042/"
ProxyPassReverse "/" "http://localhost:8042/"
ErrorLog /var/log/apache2/orthanc-error.log
CustomLog /var/log/apache2/orthanc-access.log combined
LogLevel error
</VirtualHost>
答案2
至少目前找到了一种让它工作的方法。这是现在的配置:
<VirtualHost *:80>
ProxyRequests Off
RewriteEngine on
RewriteCond %{QUERY_STRING} series [OR]
RewriteCond %{QUERY_STRING} study
Rewriterule "^/osimis-viewer/app/index.html" "http://10.8.0.11:8042/osimis-vi$
Rewriterule "^/web-viewer/app/viewer.html" "http://10.8.0.11:8042/web-viewer/$
ProxyPass "/" "http://localhost:8042/"
ProxyPassReverse "/" "http://localhost:8042/"
ErrorLog /var/log/apache2/orthanc-error.log
CustomLog /var/log/apache2/orthanc-access.log combined
LogLevel error
</VirtualHost>