将配置重写为HTTPS无效

时间:2018-09-04 11:31:10

标签: apache tomcat7 centos7 httpd.conf

实际上,我在centos 7上遇到了http到https重定向(使用httpd(apache)重定向)的一些问题。 在应用程序本身上,我指定了以下URL

https://pwm.mywebsitetest.com

这是一个tomcat应用程序。 您会注意到http上的位置没有pwmAD, 就像这一样,因为如果我将其插入,当我在浏览器栏上调用链接时,会出现404错误,因为链接会像这样。 https://pwm.mywebsitetest.com/pwmAD/pwmAD/时应仅在选项卡中显示一个。 在conf文件之后, 下面的代码有什么问题?

    ######### VHOST per PWM HTTP ###########

<VirtualHost *:80>
    ServerAdmin webmaster@mywebsitetest.com
    ServerName pwm.mywebsitetest.com

    ErrorLog /var/log/httpd/pwm-error_log
    CustomLog /var/log/httpd/pwm-access_log combinedXForwardedFor env=!dontlog

    RewriteEngine on
    RewriteRule ^/$ https://pwm.mywebsitetest.com [L,R=302]

    ProxyPreserveHost On
    ProxyRequests     Off

  <Location "/">
   ProxyPass http://pwm.mywebsitetest.com:8080/
   ProxyPassReverse http://pwm.mywebsitetest.com:8080/
  </Location>
</VirtualHost>

########## VHOST per PWM HTTPS ###########
<VirtualHost *:443>
    ServerAdmin webmaster@mywebsitetest.com
    ServerName pwm.mywebsitetest.com

    SSLEngine on
    SSLProxyEngine on
    SSLStrictSNIVHostCheck off
    SSLProtocol all -SSLv2 -SSLv3
    SSLCertificateFile /etc/pki/tls/certs/cert_com.crt
    SSLCertificateKeyFile /etc/pki/tls/private/cert_com.key
    SSLCACertificateFile /etc/pki/tls/certs/cert_CA_Bundle.pem

    ErrorLog /var/log/httpd/pwm-error_log
    CustomLog /var/log/httpd/pwm-access_log combinedXForwardedFor env=!dontlog
     ProxyPreserveHost On
     ProxyRequests     Off

        <Location "/">
                ProxyPass  http://pwm.mywebsitetest.com:8080/pwmAD/
                ProxyPassReverse  http://pwm.mywebsitetest.com:8080/pwmAD/
        </Location>
</VirtualHost>

1 个答案:

答案 0 :(得分:0)

如果要将所有http请求都重定向到https,则:80 VirtualHost中所需的全部是:

<VirtualHost *:80>
    ServerAdmin webmaster@mywebsitetest.com
    ServerName pwm.mywebsitetest.com

    ErrorLog /var/log/httpd/pwm-error_log
    CustomLog /var/log/httpd/pwm-access_log combinedXForwardedFor env=!dontlog

    Redirect / https://pwm.mywebsitetest.com/
</VirtualHost>