As Tomcat is not a true web server, it's worth to use it as backend. Nginx is one of the best solutions for the frontend web server.
So, after a typical XWiki installation we have XWiki running on http://localhost:8080/xwiki. Most probably, we want to access XWiki viahttp://mydomain.com on standard 80 port. Tuning Nginx will give us the desired result:
- create this file /etc/nginx/conf.d/tomcat.conf
- put the following code inside:
server {
listen 80;
server_name mydomain.com;
# Root to the XWiki application
root opt/tomcat/webapps/xwiki;
location / {
#All "root" requests will have /xwiki appended AND redirected to mydomain.com again
rewrite ^ $scheme://$server_name/xwiki$request_uri? permanent;
}
location ^~ /xwiki {
# If path starts with /xwiki - then redirect to backend: XWiki application in Tomcat
proxy_pass http://localhost:8080/xwiki;
}
} - restart nginx
Now all http://mydomain.com/* requests will lead to the XWiki application. Please note that these settings are basic. For more flexible solutions please refer to the Nginx documentation.