Goal
- 80 port proxy to 8080 port. If work, will show ‘proxy’
http://localhost:8080
can’t access, must return 404.- Use
<If "%{SERVER_PORT} != '80'"> Redirect 404 / </If>
- Use
Repo & Env Set
source code :
https://github.com/jhaoheng/apacheProxy&UseExpressions
docker-compose up -d
&&docker exec -it ubuntu /bin/bash
apt-get update
apt-get install -y libapache2-mod-proxy-html libxml2-dev apache2 build-essential
- Proxy Modules
a2enmod proxy proxy_http proxy_ajp rewrite proxy_balancer proxy_connect proxy_html xml2enc
Steps
ref
./default.conf
&ports.conf
step1 : enable port 8080
- update
ports.conf
in the ‘/etc/apache2/ports’ Listen 8080
step2 : set VirtualHost
echo "proxy" > /var/www/proxy/index.html
- set VirtualHost ```
<VirtualHost *:8080> ServerName localhost DocumentRoot /var/www/proxy/ </VirtualHost>
1 |
|
Proxy
ProxyRequests Off ProxyPass / http://localhost:8080 ProxyPassReverse / http://localhost:8080 ProxyPreserveHost On
1 |
|
AllowCONNECT 80 <If “%{SERVER_PORT} != ‘80’”> Redirect 404 / </If> ```
- Expressions in Apache HTTP Server
- https://httpd.apache.org/docs/current/expr.html
step5 : restart & check it
apache2ctl restart
http://localhost:80
, will show ‘proxy’http://localhost:8080
, be restricted to access