Apache2反向代理 – 不同的处理或url

我正在努力与反向代理configuration和具体的重写/ proxypass取决于URLpath。

SZENARIO:

  • DMZ中的反向代理
  • SSL在反向代理上结束
  • 请求应通过http传递给内部服务器
  • HTTP需要重写为HTTPS
  • 在html hrefs中,像“/system/js/abc.js”

我目前的configuration:

<VirtualHost *:80> ServerName media.customer.com RewriteEngine On RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$ RewriteRule ^(.*)$ https://media.customer.com$1 [R=301,L] </VirtualHost> <VirtualHost *:443> ServerName media.customer.com DocumentRoot /var/www/customer.com/ SSLEngine On SSLCertificateKeyFile /etc/apache2/certs/server.key SSLCertificateFile /etc/apache2/certs/server.crt ProxyRequests Off ProxyPass / http://serverName/ ProxyPassReverse / http://serverName/ ProxyHTMLEnable On ProxyHTMLURLMap http://serverName/ / </VirtualHost> 

这不会是一个大问题,但我们需要得到以下规则工作:

  1. 只有base-url“Http:// serverName”路由到http:// serverName / system / (add / system /)到base-URL
  2. 每个更深的URL只有协议从http更改为https。 没有更改url。
  3. 绝对http-URL需要更改为https-URL

上面的configuration适用于:

  • [HTTP] /服务器名/系统/
  • [HTTP] /服务器名/系统
  • [HTTPS] /服务器名/系统/
  • [HTTPS] /服务器名/系统
  • [HTTP] /serverName/system/img/test.gif
  • [HTTPS] /serverName/system/img/test.gif

我把“/ fotoweb /”放在RewriteRule或ProxyPass中,我们得到了两倍的string: http://serverName/system/system/img/test.gif

对于我的意见,我需要确定它的基地址,然后添加“/系统/”,否则只是映射到http。 但不知道如何做到这一点。

提前致谢!

这将所有不是HTTPS的内容重写为HTTPS:

 RewriteCond %{HTTPS} !=on RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] 

不知道你认为“base-url”,但我假设它是HTTPS +不是以'/ system'开头。 这会将所有不以'/ system'开始的内容重写为'/ system / …':

 RewriteCond %{REQUEST_URI} ! ^/system RewriteRule .* /system%{REQUEST_URI} [R=301,L] 

如果只是“/”,那么:

 RewriteCond %{REQUEST_URI} ^/$ RewriteRule .* /system/ [R=301,L] 

一体:

 <VirtualHost *:80> ServerName media.customer.com RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] </VirtualHost> <VirtualHost *:443> ServerName media.customer.com RewriteEngine on RewriteCond %{REQUEST_URI} ! ^/system RewriteRule .* /system%{REQUEST_URI} [R=301,L] DocumentRoot /var/www/customer.com/ SSLEngine On SSLCertificateKeyFile /etc/apache2/certs/server.key SSLCertificateFile /etc/apache2/certs/server.crt ProxyRequests Off ProxyPass / http://serverName/ ProxyPassReverse / http://serverName/ ProxyHTMLEnable On ProxyHTMLURLMap http://serverName/ / </VirtualHost>