Last active
January 27, 2020 02:48
-
-
Save Martlark/3f42bd1a227f167dc8349294a13efe54 to your computer and use it in GitHub Desktop.
Reverse proxy conf for a Docker application using an Apache proxy with letsencrypt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Define HOST example | |
Define HOST_URL www.${HOST}.com | |
Define DOCKER_PORT 8083 | |
<VirtualHost *:80> | |
ServerName ${HOST_URL} | |
ServerAlias ${HOST}.com | |
Redirect permanent / https://${HOST_URL}/ | |
</VirtualHost> | |
<VirtualHost *:443> | |
ServerName ${HOST_URL} | |
ServerAlias ${HOST}.com | |
# proxy | |
ProxyPass / http://localhost:${DOCKER_PORT}/ nocanon | |
ProxyPassReverse / http://localhost:${DOCKER_PORT}/ | |
ProxyPreserveHost On | |
RewriteEngine On | |
# Redirect to the correct domain name | |
RewriteCond %{HTTP_HOST} !^${HOST_URL}$ [NC] | |
RewriteRule .* - [E=SERVER_PORT:%{SERVER_PORT},NE,L] | |
# substitute docker host for external host | |
AddOutputFilterByType SUBSTITUTE text/html | |
Substitute "s|http://localhost:${DOCKER_PORT}/|https://${HOST_URL}/|i" | |
RequestHeader set X_TRUE_IP "%{REMOTE_ADDR}s" | |
RequestHeader set X-Forwarded-Port %{SERVER_PORT}e | |
RequestHeader set X-Forwarded-Scheme https | |
# lets encrypt | |
Include /etc/letsencrypt/options-ssl-apache.conf | |
SSLCertificateFile /etc/letsencrypt/live/${HOST_URL}/fullchain.pem | |
SSLCertificateKeyFile /etc/letsencrypt/live/${HOST_URL}/privkey.pem | |
</VirtualHost> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment