我的conf文件中有2个虚拟主机标签。
第一个标签包含通过内部IP地址发出请求的重定向规则。
第二个标记包含通过公共IP或任何其他地方发出请求的其他重定向规则
当我删除第一个VirtualHost标记时,重定向和ssl完全正常,但我还需要第一个VirtualHost标记
位于/etc/apache2/sites-available/site.conf
<VirtualHost 10.1.0.7:80>
ProxyPreserveHost On
LogLevel debug
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName servername.com
ProxyPass /Service http://localhost:8080/Service
ProxyPassReverse /Service http://localhost:8080/Service
</VirtualHost>
<VirtualHost *:80>
ProxyPreserveHost On
LogLevel debug
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName servername.com
RewriteEngine On # Turn on the rewriting engine
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
</VirtualHost>
位于/etc/apache2/sites-available/site-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
LogLevel debug
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPreserveHost On
ServerName server.com
# Redirections:
ProxyPass /server-status http://localhost:7570/server-status
ProxyPassReverse /server-status http://localhost:7570/server-status
ProxyPass /mCare/subscribe ws://localhost:8080/mCare/subscribe
ProxyPassReverse /mCare/subscribe ws://localhost:8080/mCare/subscribe
ProxyPass /mCare http://localhost:8080/mCare
ProxyPassReverse /mCare http://localhost:8080/mCare
ProxyPass /solr http://localhost:8280/solr
ProxyPassReverse /solr http://localhost:8280/solr
SSLEngine on
SSLCertificateFile /mnt/opt/ssl/2015/sha2/b89516b0cdc9a701.crt
SSLCertificateKeyFile /mnt/opt/ssl/2015/sha2/mcare.pem
SSLCertificateChainFile /mnt/opt/ssl/2015/sha2/gd_bundle.crt
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>
这是我的ports.conf文件:
Listen 80
<IfModule ssl_module>
Listen 443
</IfModule>
答案 0 :(得分:0)
我终于让它发挥作用了。
我发布此内容,以便面临同一问题的其他人可以获得帮助。
我只是 使用服务器的内部IP避免虚拟主机标记 ,并设法在RewriteRule中编写更好的正则表达式
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass /Service http://localhost:8080/Service
ProxyPassReverse /Service http://localhost:8080/Service
LogLevel debug
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName server.com
RewriteEngine On # Turn on the rewriting engine
RewriteCond %{HTTPS} !=on
RewriteRule ^((?!/Service).)*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
</VirtualHost>
现在,我的 /etc/apache2/sites-available/site.conf 文件只包含一个虚拟标记。
我编写了表达式,以便包含Service的所有请求都不需要重定向到https,并且我也为此提供了proxyPass。
如果任何人有更好的解决方案,那么也欢迎您的回答