帶有代理和 ssl 的 Apache 未偵聽連接埠 80

帶有代理和 ssl 的 Apache 未偵聽連接埠 80

我在 ubuntu 18.04 中運行 apache 2.4.29,並且在 000-default.conf 中有以下設置

 <VirtualHost *:80>
  ServerName example.com
  Redirect permanent / https://example.com/
</VirtualHost>

<VirtualHost *:443>

    ServerName example.com
    DocumentRoot /var/www/html

    LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error_ssl.log
    CustomLog ${APACHE_LOG_DIR}/access_ssl.log combined

    SSLEngine on
    SSLProxyEngine On

    SSLCertificateKeyFile /pathtokey/privkey.pem
    SSLCertificateChainFile /pathtokey/chain.pem
    SSLCertificateFile /pathtokey/fullchain.pem

    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass / https://localhost:8443/
    ProxyPassReverse / https://localhost:8443/


    #ErrorLog ${APACHE_LOG_DIR}/error.log
    #CustomLog ${APACHE_LOG_DIR}/access.log combined


</VirtualHost>

Apache 充當 tomcat 伺服器的代理,兩者都使用 SSL。如果我使用帶有 https 的 url,apache 運行良好,但是當我嘗試使用 http 時,我無法重定向到 https。我檢查了一下,似乎 apache 不偵聽或處理來自連接埠 80 的連線(我也檢查了 telnet)

如果我刪除 SSL 設置,並在連接埠 80 中保留一個虛擬主機,我可以在沒有 SSL 的情況下工作,這在連接埠 80 中工作正常,但是當我啟用 ssl 時,我只能使用帶有 https 的伺服器

有什麼辦法可以使用http並重定向到https嗎?

答案1

我發現了問題:我在 IPTABLES 中有一個路由將流量從連接埠 80 發送到 8080

相關內容