Apache reverse proxy y virtualhosts
Apache reverse proxy y virtualhosts
Apache reverse proxy y virtualhosts
Este post cubre la creacion de virtualhosts, redirecciones HTTPS y publicacion de aplicaciones mediante reverse proxy con Apache/httpd.
Instalacion basica
1
2
3
4
yum install -y httpd mod_ssl
systemctl enable httpd
systemctl start httpd
systemctl status httpd
En Debian/Ubuntu:
1
2
3
4
apt install -y apache2 libapache2-mod-proxy-html
a2enmod proxy proxy_http proxy_wstunnel ssl headers rewrite
systemctl enable apache2
systemctl restart apache2
Virtualhost simple
1
2
3
4
5
6
7
8
9
10
11
12
13
<VirtualHost *:80>
ServerName app.example.local
DocumentRoot /var/www/app
ErrorLog /var/log/httpd/app-error.log
CustomLog /var/log/httpd/app-access.log combined
<Directory /var/www/app>
Require all granted
Options -Indexes +FollowSymLinks
AllowOverride None
</Directory>
</VirtualHost>
Reverse proxy HTTP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<VirtualHost *:443>
ServerName app.example.local
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/app.example.local.crt
SSLCertificateKeyFile /etc/pki/tls/private/app.example.local.key
ProxyPreserveHost On
ProxyPass / http://backend.example.local:8080/
ProxyPassReverse / http://backend.example.local:8080/
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Forwarded-Port "443"
ErrorLog /var/log/httpd/app-proxy-error.log
CustomLog /var/log/httpd/app-proxy-access.log combined
</VirtualHost>
Redireccion de HTTP a HTTPS
1
2
3
4
<VirtualHost *:80>
ServerName app.example.local
Redirect permanent / https://app.example.local/
</VirtualHost>
Comprobaciones rapidas
1
2
3
4
apachectl configtest
httpd -M | grep -E 'proxy|ssl|headers|rewrite'
curl -Ik https://app.example.local/
tail -f /var/log/httpd/app-proxy-error.log
Proxy con backend externo
1
2
3
4
ProxyPreserveHost On
ProxyPass /api/ https://api.example.local/
ProxyPassReverse /api/ https://api.example.local/
RequestHeader set X-Forwarded-Proto "https"
This post is licensed under CC BY 4.0 by the author.