Apache/Proxy: Difference between revisions
< Apache
(Created page with "== Proxy ==") |
No edit summary |
||
| Line 1: | Line 1: | ||
== Proxy == | == Proxy Pass == | ||
Enable Proxy: [https://www.digitalocean.com/community/tutorials/how-to-use-apache-as-a-reverse-proxy-with-mod_proxy-on-ubuntu-16-04] | |||
sudo a2enmod proxy | |||
sudo a2enmod proxy_http | |||
systemctl restart apache2 | |||
Similar to forwarding, but takes care of redirects: | |||
ProxyPass /mirror/foo/ http://foo.com/ | |||
ProxyPassReverse /mirror/foo/ http://foo.com/ | |||
Suppose the local server has address http://wibble.org/; then | |||
ProxyPass /mirror/foo/ http://foo.com/ | |||
ProxyPassReverse /mirror/foo/ http://foo.com/ | |||
will not only cause a local request for the <http://wibble.org/mirror/foo/bar> to be internally converted into a proxy request to <http://foo.com/bar> (the functionality ProxyPass provides here). It also takes care of redirects the server foo.com sends: when http://foo.com/bar is redirected by him to http://foo.com/quux Apache adjusts this to http://wibble.org/mirror/foo/quux before forwarding the HTTP redirect response to the client. | |||
<pre> | |||
<VirtualHost *:80> | |||
ServerName wiki.oeey.com | |||
# Reverse Proxy | |||
ProxyPass / http://localhost:8080/ | |||
ProxyPassReverse / http://localhost:8080/ | |||
ServerAdmin website@oeey.com | |||
ErrorLog logs/wiki-error_log | |||
CustomLog logs/wiki-access_log common | |||
</VirtualHost> | |||
</pre> | |||
Proxy Pass to Jenkins: [https://wiki.jenkins-ci.org/display/JENKINS/Running+Jenkins+behind+Apache] | |||
<pre> | |||
NameVirtualHost *:80 | |||
<VirtualHost *:80> | |||
ServerName jenkins.oeey.com | |||
#Forwarding Traffic | |||
#RewriteEngine on | |||
#RewriteRule ^(/.*) http://localhost:8080/$1 [P] | |||
ProxyPass / http://localhost:8080/ nocanon | |||
ProxyPassReverse / http://localhost:8080/ | |||
ProxyRequests Off | |||
ProxyPreserveHost On | |||
AllowEncodedSlashes NoDecode | |||
# Local reverse proxy authorization override | |||
# Most unix distribution deny proxy by default (ie /etc/apache2/mods-enabled/proxy.conf in Ubuntu) | |||
<Proxy http://localhost:8080/*> | |||
Order deny,allow | |||
Allow from all | |||
</Proxy> | |||
ServerAdmin admin@oeey.com | |||
ErrorLog logs/jenkins.oeey.com-error_log | |||
CustomLog logs/jenkins.oeey.com-access_log common | |||
</VirtualHost> | |||
</pre> | |||
=== Proxy Pass HTTPS === | |||
Proxy Pass to Jenkins: | |||
<pre> | |||
NameVirtualHost *:443 | |||
<VirtualHost *:443> | |||
ServerName jenkins.oeey.com | |||
# Enable SSL Support | |||
SSLEngine on | |||
SSLCertificateFile /etc/pki/tls/certs/localhost.crt | |||
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key | |||
#Forwarding Traffic | |||
#RewriteEngine on | |||
#RewriteRule ^(/.*) http://localhost:8080/$1 [P] | |||
ProxyPass / http://localhost:8080/ nocanon | |||
ProxyPassReverse / http://localhost:8080/ | |||
ProxyPassReverse / http://jenkins.oeey.com/ | |||
ProxyRequests Off | |||
ProxyPreserveHost On | |||
AllowEncodedSlashes NoDecode | |||
RequestHeader set X-Forwarded-Proto "http" | |||
# Local reverse proxy authorization override | |||
# Most unix distribution deny proxy by default (ie /etc/apache2/mods-enabled/proxy.conf in Ubuntu) | |||
<Proxy http://localhost:8080/jenkins*> | |||
Order deny,allow | |||
Allow from all | |||
</Proxy> | |||
ServerAdmin admin@oeey.com | |||
ErrorLog logs/jenkins.oeey.com-error_log | |||
CustomLog logs/jenkins.oeey.com-access_log common | |||
</VirtualHost> | |||
</pre> | |||
Latest revision as of 00:33, 28 September 2026
Proxy Pass
Enable Proxy: [1]
sudo a2enmod proxy sudo a2enmod proxy_http systemctl restart apache2
Similar to forwarding, but takes care of redirects:
ProxyPass /mirror/foo/ http://foo.com/ ProxyPassReverse /mirror/foo/ http://foo.com/
Suppose the local server has address http://wibble.org/; then
ProxyPass /mirror/foo/ http://foo.com/ ProxyPassReverse /mirror/foo/ http://foo.com/
will not only cause a local request for the <http://wibble.org/mirror/foo/bar> to be internally converted into a proxy request to <http://foo.com/bar> (the functionality ProxyPass provides here). It also takes care of redirects the server foo.com sends: when http://foo.com/bar is redirected by him to http://foo.com/quux Apache adjusts this to http://wibble.org/mirror/foo/quux before forwarding the HTTP redirect response to the client.
<VirtualHost *:80>
ServerName wiki.oeey.com
# Reverse Proxy
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
ServerAdmin website@oeey.com
ErrorLog logs/wiki-error_log
CustomLog logs/wiki-access_log common
</VirtualHost>
Proxy Pass to Jenkins: [2]
NameVirtualHost *:80
<VirtualHost *:80>
ServerName jenkins.oeey.com
#Forwarding Traffic
#RewriteEngine on
#RewriteRule ^(/.*) http://localhost:8080/$1 [P]
ProxyPass / http://localhost:8080/ nocanon
ProxyPassReverse / http://localhost:8080/
ProxyRequests Off
ProxyPreserveHost On
AllowEncodedSlashes NoDecode
# Local reverse proxy authorization override
# Most unix distribution deny proxy by default (ie /etc/apache2/mods-enabled/proxy.conf in Ubuntu)
<Proxy http://localhost:8080/*>
Order deny,allow
Allow from all
</Proxy>
ServerAdmin admin@oeey.com
ErrorLog logs/jenkins.oeey.com-error_log
CustomLog logs/jenkins.oeey.com-access_log common
</VirtualHost>
Proxy Pass HTTPS
Proxy Pass to Jenkins:
NameVirtualHost *:443
<VirtualHost *:443>
ServerName jenkins.oeey.com
# Enable SSL Support
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
#Forwarding Traffic
#RewriteEngine on
#RewriteRule ^(/.*) http://localhost:8080/$1 [P]
ProxyPass / http://localhost:8080/ nocanon
ProxyPassReverse / http://localhost:8080/
ProxyPassReverse / http://jenkins.oeey.com/
ProxyRequests Off
ProxyPreserveHost On
AllowEncodedSlashes NoDecode
RequestHeader set X-Forwarded-Proto "http"
# Local reverse proxy authorization override
# Most unix distribution deny proxy by default (ie /etc/apache2/mods-enabled/proxy.conf in Ubuntu)
<Proxy http://localhost:8080/jenkins*>
Order deny,allow
Allow from all
</Proxy>
ServerAdmin admin@oeey.com
ErrorLog logs/jenkins.oeey.com-error_log
CustomLog logs/jenkins.oeey.com-access_log common
</VirtualHost>