Configure Apache HTTP Server as a Proxy on a Linux OS
Tutorial
Apache HTTP Server forwards requests to the XWiki Servlet Container on a Linux system, using the directives XWiki needs. This procedure serves the wiki over plain HTTP on port 80; Configure HTTPS for the Apache HTTP Proxy Server adds HTTPS on top of it. The commands are those of a Debian-based distribution.
- Make sure your wiki is running and reachable locally, for example at
http://localhost:8080/xwiki. - Install Apache HTTP Server, version 2.4.47 or later, which is what the upgrade=websocket option below needs.
- Enable the modules the configuration below needs:
sudo a2enmod proxy proxy_http headers. - Create the file /etc/apache2/sites-available/xwiki.conf with the following content:
<VirtualHost *:80> ServerName localhost ErrorLog ${APACHE_LOG_DIR}/xwiki-error.log CustomLog ${APACHE_LOG_DIR}/xwiki-access.log combined RedirectMatch ^/$ /xwiki/ <Location /xwiki> Require all granted </Location> AllowEncodedSlashes NoDecode RequestHeader unset Forwarded RequestHeader unset X-Forwarded-Host RequestHeader unset X-Forwarded-Proto ProxyRequests Off ProxyPreserveHost On ProxyPass /xwiki http://localhost:8080/xwiki nocanon upgrade=websocket ProxyPassReverse /xwiki http://localhost:8080/xwiki </VirtualHost> - Enable the site:
sudo a2ensite xwiki. - Check the configuration:
sudo apachectl configtest. - Reload Apache:
sudo systemctl reload apache2. - Open
http://localhostin a browser. Apache redirects tohttp://localhost/xwiki/and the wiki loads through port 80, with no port number in the address.
FAQ
Why does the configuration file have to be enabled separately?
Apache only reads the files in /etc/apache2/sites-enabled/, and a2ensite is what creates the symbolic link there to the file in sites-available.
What differs on a distribution that is not Debian-based?
On Red Hat based systems the service is named httpd, the same VirtualHost block goes into a file under /etc/httpd/conf.d/, and the modules are loaded by LoadModule lines in /etc/httpd/conf/httpd.conf instead of by a2enmod. Red Hat Enterprise Linux 8 ships Apache HTTP Server 2.4.37, which cannot parse upgrade=websocket and refuses to start: drop that option there and tunnel the WebSocket connections with mod_proxy_wstunnel instead, by adding ProxyPass /xwiki/websocket ws://localhost:8080/xwiki/websocket above the /xwiki rule, where the more specific path has to come first.