Setting up the Apache HTTP Server Proxy
Last modified by Vincent Massol on 2025/01/13
Example inspired from the config for https://www.myxwiki.org (with only the important parts):
- Any acces to port 80 redirect to port 443
- Proxy the port 443 to the port 8080 (where most application servers are listening by default)
- Redirect / access to /xwiki/
- Make sure XWiki have enough information to know what is the source URL
- Make sure that special characters like / and + are allowed by Apache
- Mind the "noncanon" keyword. Without it, URLs containing semicolons will be mangled
- Enable WebSocket
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias *.mydomain.com
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
</VirtualHost>
<VirtualHost *:443>
ServerName mydomain.com
ServerAlias *.mydomain.com
DocumentRoot /var/www/
ErrorLog /var/log/apache2/xwiki-error.log
CustomLog /var/log/apache2/xwiki-access.log combined
RedirectMatch ^/$ /xwiki/
<Location /xwiki>
Order Deny,Allow
Satisfy Any
</Location>
AllowEncodedSlashes NoDecode
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost On
ProxyPass /xwiki http://localhost:8080/xwiki nocanon upgrade=websocket
ProxyPassReverse /xwiki http://localhost:8080/xwiki nocanon
## Workaround for https://bz.apache.org/bugzilla/show_bug.cgi?id=58001 (ProxyPreserveHost does not includes Forwarded)
RequestHeader set Forwarded "proto=https"
# TODO: add your SSL setup
</VirtualHost>
ServerName mydomain.com
ServerAlias *.mydomain.com
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
</VirtualHost>
<VirtualHost *:443>
ServerName mydomain.com
ServerAlias *.mydomain.com
DocumentRoot /var/www/
ErrorLog /var/log/apache2/xwiki-error.log
CustomLog /var/log/apache2/xwiki-access.log combined
RedirectMatch ^/$ /xwiki/
<Location /xwiki>
Order Deny,Allow
Satisfy Any
</Location>
AllowEncodedSlashes NoDecode
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost On
ProxyPass /xwiki http://localhost:8080/xwiki nocanon upgrade=websocket
ProxyPassReverse /xwiki http://localhost:8080/xwiki nocanon
## Workaround for https://bz.apache.org/bugzilla/show_bug.cgi?id=58001 (ProxyPreserveHost does not includes Forwarded)
RequestHeader set Forwarded "proto=https"
# TODO: add your SSL setup
</VirtualHost>