Deploying Web App with Docker + Apache Reverse Proxy
Contents
1) Apache as Reverse Proxy
Use Apache on host to forward traffic to Docker containers.
Key points:
ProxyPreserveHost On
RequestHeader set X-Forwarded-Proto "https"
These keep the real domain instead of 127.0.0.1 inside Docker.
Example:
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
2) Enable Required Apache Modules
sudo a2enmod proxy proxy_http headers rewrite ssl
sudo systemctl reload apache2
3) Allow .htaccess
In vhost:
<Directory /var/www/html>
AllowOverride All
Require all granted
</Directory>
AllowOverride None disables .htaccess.
4) HTTPS with Certbot
If certbot --apache hangs:
sudo apachectl configtest
sudo ss -lntp | grep :80
sudo ufw allow 80
sudo ufw allow 443
sudo certbot --apache -v
Fallback:
sudo certbot certonly --standalone
5) Fix Base URL in Docker (CodeIgniter)
Because Docker sees 127.0.0.1, use forwarded headers.
Apache:
ProxyPreserveHost On
RequestHeader set X-Forwarded-Proto "https"
PHP:
$scheme = $_SERVER['HTTP_X_FORWARDED_PROTO'] ?? 'http';
$host = $_SERVER['HTTP_X_FORWARDED_HOST'] ?? $_SERVER['HTTP_HOST'];
$config['base_url'] = $scheme.'://'.$host.'/';
Or in CI3:
$config['base_url'] = '';
6) Redirect HTTP → HTTPS
RewriteEngine On
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
7) Debugging
- List proxy rules:
grep -R "ProxyPass" /etc/apache2/
- Check proxy modules:
apachectl -M | grep proxy
- Logs:
tail -f /var/log/apache2/error.log
8) Ownership / Permissions
chown -R $USER:www-data /path/to/app
chmod -R 750 /path/to/app
find /path/to/app -type f -exec chmod 640 {} +
chmod -R 775 /path/to/app/asset/{files,foto_banner,foto_berita,foto_info,img_album,img_galeri,slide_header}
chmod 664 /path/to/app/rss.xml