First, let's verify the core configuration elements for a working reverse proxy setup:
# Required modules (execute in terminal)
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo systemctl restart apache2
Your current VirtualHost configuration has several potential issues. Here's an improved version with detailed comments:
ServerName yourdomain.local
ServerAlias localhost
# Essential proxy directives
ProxyRequests Off
ProxyPreserveHost On
# Security controls
Require all granted
# Main proxy rules
ProxyPass / http://www.google.de/ nocanon
ProxyPassReverse / http://www.google.de/
# Additional recommended headers
RequestHeader set Host "www.google.de"
# Error logging (crucial for debugging)
ErrorLog ${APACHE_LOG_DIR}/proxy_error.log
LogLevel debug
1. Port Binding Issues: Ensure Apache is actually listening on port 8080:
# Check listening ports
netstat -tulnp | grep apache
2. DNS Resolution Problems: Add the domain to your /etc/hosts file:
127.0.0.1 yourdomain.local
3. SELinux Restrictions (for CentOS/RHEL):
setsebool -P httpd_can_network_connect 1
Enable detailed logging by adding these directives to your VirtualHost:
LogLevel debug proxy:trace5
CustomLog ${APACHE_LOG_DIR}/access_proxy.log "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
Key things to check in logs:
- Is the request reaching the correct VirtualHost?
- Are the ProxyPass rules being evaluated?
- Any connection errors to the backend?
For testing purposes, try this minimal working example:
ProxyPass / http://example.com/
ProxyPassReverse / http://example.com/
Then gradually add complexity (port changes, headers, etc.) while testing at each step.
When proxying to external domains, these directives can help:
# Timeout settings
ProxyTimeout 300
# Connection pooling
ProxySet connectiontimeout=5 timeout=30
# Disable SSL verification for HTTPS proxies
SSLProxyEngine on
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
When testing a basic reverse proxy configuration that should redirect all traffic to Google, many developers encounter the frustrating scenario where Apache stubbornly serves its default "It works!" page instead. Let's dissect this common issue with a working solution.
Your current VirtualHost setup has several potential issues:
<VirtualHost 192.168.1.2:8080>
ServerName localhost
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://www.google.de/
ProxyPassReverse / http://www.google.de/
</VirtualHost>
1. Port Conflict: Port 8080 might be occupied or not properly listened to
# Check listening ports
netstat -tulnp | grep 8080
2. Missing ServerName: The VirtualHost needs explicit ServerName directive
ServerName localhost
3. Modern Access Control: Update from Order/Allow to Require syntax
# Old (Apache 2.2)
Order deny,allow
Allow from all
# New (Apache 2.4+)
Require all granted
Here's a verified working setup:
<VirtualHost *:80>
ServerName proxy-test.local
DocumentRoot /var/www/html
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://www.google.com/
ProxyPassReverse / http://www.google.com/
ErrorLog ${APACHE_LOG_DIR}/proxy-error.log
CustomLog ${APACHE_LOG_DIR}/proxy-access.log combined
</VirtualHost>
After implementing the fixes:
# Check syntax
apachectl configtest
# Reload configuration
systemctl reload apache2
# Test with curl
curl -v http://localhost -H "Host: proxy-test.local"
- Ensure
a2enmod proxy proxy_http
is executed - Verify SELinux/AppArmor isn't blocking proxy connections
- Check firewall rules for outbound connections
- Inspect Apache error logs for detailed failure reasons