WebServer - Proxy VirtualHost Configuration

From The TinkerNet Wiki
Revision as of 13:05, 15 July 2020 by Tinker (talk | contribs)
Jump to navigation Jump to search

An Example:

  • FQDN being proxied
    • Test.Domain.Net
  • Internal server FQDN
    • Server.LocalDomain.net
#########################
# Test.Domain.Net       #
#########################

# Proxy the local machine name for completeness
<VirtualHost *:80>
    ServerName Server.LocalDomain.net
    Redirect permanent / https://Test.Domain.Net/
</VirtualHost>

# Enforce use of SSL
<VirtualHost *:80>
    ServerName Test.Domain.Net
    Redirect permanent / https://Test.Domain.Net/
</VirtualHost>

# The actual proxy definition
<VirtualHost _default_:443>
    ServerName Test.Domain.Net
    ProxyRequests on
    SSLEngine On
    SSLProxyEngine On
    ProxyPreserveHost Off

    # Redirect HTTPS traffic
    ProxyPass / https://Server.LocalDomain.net/
    ProxyPassReverse / https://Server.LocalDomain.net/

    SSLCertificateFile /etc/letsencrypt/live/Test.Domain.Net/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/Test.Domain.Net/privkey.pem
    <Proxy "*">
        Order allow,deny
        Allow from all
    </Proxy>
    ErrorLog /var/log/apache2/Proxy/TDN.log
    CustomLog /var/log/apache2/Proxy/TDN-access.log combined
</VirtualHost>

This can be placed in a file in /etc/apache2/sites-available (And, of course, linked into /etc/apache2/sites-enabled)