Configure NginX Server as a Proxy on a Linux OS
Tutorial
NginX 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 NginX 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 NginX.
- Create the file /etc/nginx/sites-available/xwiki with the following content:
map $http_upgrade $connection_upgrade { default upgrade; "" ""; } server { listen 80; server_name localhost; access_log /var/log/nginx/xwiki-access.log; error_log /var/log/nginx/xwiki-error.log; client_max_body_size 0; location = / { return 301 /xwiki/; } location /xwiki { proxy_pass http://localhost:8080; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header Forwarded ""; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_redirect off; } } - Enable the site:
sudo ln -s /etc/nginx/sites-available/xwiki /etc/nginx/sites-enabled/. - Check the configuration:
sudo nginx -t. - Reload NginX:
sudo systemctl reload nginx. - Open
http://localhostin a browser. NginX 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?
The nginx.conf the Debian packages ship includes /etc/nginx/sites-enabled/, and nothing else, so the symbolic link created above is what makes NginX read the file written in sites-available. Keeping the two directories apart is what lets a site be disabled without deleting its configuration.
How do I serve the wiki on my own domain instead of localhost?
Set server_name to that domain, for example server_name wiki.example.com;, and make sure the name resolves: a name that is not published in DNS has to be added to the hosts file of every machine that uses it, for example 127.0.0.1 wiki.example.local.
Where does NginX write its logs?
In the two files named by the block above, /var/log/nginx/xwiki-access.log and /var/log/nginx/xwiki-error.log. The access log is where to look first when the wiki answers through port 8080 but not through the proxy, since it records the path NginX actually forwarded.