How to configure Apache reverse proxy domain url to specific url on localhost

北城以北 提交于 2019-12-13 03:35:33

问题


I am stuck with an issue i have with configuring apache reverse proxy server. I want to use an url eq.: https://software.testsite.net and my reverse proxy should be configured using http://localhost:82/customapp.

The problem currently when i navigate to https://www.testsite.net it is replaced with http://localhost:82/customapp.

How do i go about configuring this? My configuration:

<VirtualHost *:443>
    SSLEngine on
    ServerName software.testsite.net
    SSLProxyEngine On

    SSLCertificateFile "${SRVROOT}/certs/testsite.crt"
    SSLCertificateKeyFile "${SRVROOT}/certs/testsite.key"
    SSLCertificateChainFile "${SRVROOT}/certs/testsite.ca-bundle"

    RequestHeader edit Destination ^https http early

    <Location />
        RedirectMatch ^/$ https://localhost:82/customapp
        ProxyPass http://localhost:82/customapp
        ProxyPassReverse http://localhost:82/customapp
    </Location>
</virtualhost>

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyVia on
    RewriteEngine on
    ProxyRequests     Off
    SSLProxyEngine On
    SSLCertificateFile "${SRVROOT}/certs/testsite.crt"
    SSLCertificateKeyFile "${SRVROOT}/certs/testsite.key"
    SSLCertificateChainFile "${SRVROOT}/certs/testsite.ca-bundle"

    # used for enforcing http to https
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{SERVER_NAME}$1 [R,L]

    ServerName software.testsite.net
    <Location />
        ProxyPass http://localhost:82/customapp
        ProxyPassReverse http://localhost:82/customapp
    </Location>

</VirtualHost>

回答1:


I finally got it working. Not sure if this is the way it is supposed to be done though.

<VirtualHost *:80>
    ServerName software.testsite.net

    DocumentRoot "${SRVROOT}/htdocs/software"
    DirectoryIndex index.html

    ProxyPreserveHost On
    ProxyVia on
    RewriteEngine on
    ProxyRequests     Off

    # used for enforcing http to https
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{SERVER_NAME}$1 [R,L]

    SSLProxyEngine On
    SSLCertificateFile "${SRVROOT}/certs/testsite.crt"
    SSLCertificateKeyFile "${SRVROOT}/certs/testsite.key"
    SSLCertificateChainFile "${SRVROOT}/certs/testsite.ca-bundle"

    <Location /customapp>
        ProxyPass http://localhost:82/customapp
        ProxyPassReverse http://localhost:82/customapp
    </Location>
</VirtualHost>

<VirtualHost *:443>
    ServerName software.testsite.net

    DocumentRoot "${SRVROOT}/htdocs/software"
    DirectoryIndex index.html

    RequestHeader edit Destination ^https http early
    SSLEngine on
    SSLProxyEngine On
    SSLCertificateFile "${SRVROOT}/certs/testsite.crt"
    SSLCertificateKeyFile "${SRVROOT}/certs/testsite.key"
    SSLCertificateChainFile "${SRVROOT}/certs/testsite.ca-bundle"

    <Location /customapp>
        RedirectMatch ^/$ https://localhost:82/customapp
        ProxyPass http://localhost:82/customapp
        ProxyPassReverse http://localhost:82/customapp
    </Location>
</virtualhost>

<!DOCTYPE html>
<html>
   <head>
      <title>HTML Meta Tag</title>
      <meta http-equiv = "refresh" content = "1; url =http://software.testsite.net/customapp"/>
   </head>
   <body>
      <p>Redirecting...</p>
   </body>
</html>


来源:https://stackoverflow.com/questions/54257551/how-to-configure-apache-reverse-proxy-domain-url-to-specific-url-on-localhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!