I set up Nginx as reverse proxy for Tomcat following the XWiki documentation.
Everything works fine but but I cannot figure out how to change or extend the path of the URL.
The XWiki is running on http://localhost:8080/xwiki. I like to access the XWiki via wiki.mydomain.com on a standard http (80) or https (443) port (without the xwiki path).
Here is my Nginx configuration, which works fine (except for the path).
server {
listen 80;
server_name wiki.mydomain.com;
location ~ /.well-known {
allow all;
}
rewrite ^ https://$server_name$request_uri? permanent;
access_log /var/log/nginx-xwiki/access.log;
error_log /var/log/nginx-xwiki/error.log;
}
server {
listen 443;
server_name wiki.mydomain.com;
root /var/www/html;
# Configuration to avoid Request Entity too large error 413
client_max_body_size 0;
ssl on;
ssl_certificate /etc/ssl/...
ssl_certificate_key /etc/ssl/...
access_log /var/log/nginx-xwiki/access_ssl.log;
error_log /var/log/nginx-xwiki/error_ssl.log;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Scheme $scheme;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://127.0.0.1:8080;
break;
}
}
location ~ /.well-known {
allow all;
}
}
Nginx won’t let me add the path to the proxy_pass directive. I tried with a variable in my location block:
location / {
set $proxy_url http://127.0.0.1:8080/xwiki;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Scheme $scheme;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass $proxy_url;
break;
}
}
But this gives me the error ERR_TOO_MANY_REDIRECTS, when I try to access wiki.mydomain.com in the browser.
When I omit the IF statement I just get an basic menu without content and applied styles.
I also tried the slightly changed code from the thread Configure nginx as reverse proxy:
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_cache_bypass $http_upgrade;
proxy_pass http://127.0.0.1:8080/xwiki/;
}
But again I just get the start page without applied styles.
Can anyone give me a hint?