M
M
Monkz2018-07-31 17:28:17
Nginx
Monkz, 2018-07-31 17:28:17

Ngnix rewrite (cms and tomcat) - how to set it up correctly?

Good afternoon!!
Please help me with nginx and rewrites.
Initial Situation:
We had a Tomcat application that included both the frontend and part of the site for registered users. The URLs were (for example) www.server.com/news (for the front end) and www.server.com/customer/archive (for the back end).
Nginx has been configured to proxy everything to Tomcat:

location / {
    		proxy_pass http://127.0.0.1:8080/;
                    proxy_set_header Host $host;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $remote_addr;
    		proxy_set_header Client-IP $remote_addr;
            }

It was decided to install cms with php for frontend and url frontend-a became www.server.com/en/news or www.server.com/de/news, and the link for the admin panel
www.server.com/panel remained a Tomcat application and the URLs inside the application remained the same as they were:
www.server.com/customer/archive or www.server.com/dashboard, one thing - we decided to put the Tomcat application under /app/ in the url.
The correct url should be: www.server.com/app/customer/archive or www.server.com/app/dashboard
If I just change the location for Tomcat from / to /app/ :
location /app/ {
    		proxy_pass http://127.0.0.1:8080/;
                    proxy_set_header Host $host;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $remote_addr;
    		proxy_set_header Client-IP $remote_addr;
            }

Then clicking on the link in the application will redirect me to www.server.com/customer/archive. If I manually correct the url to www.server.com/ app /customer/archive - the page opens.
My question is how to configure the correct rewrite in nginx to give everything without errors, provided that we cannot change the links inside the tomcat app (they will remain like /customer/archive)?
Thanks in advance everyone for your response!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Mukovoz, 2018-08-04
@castomi

If I understood everything correctly, then it is enough that the tomcat makes the links in itself relative, and not complete. In this case, when proxying, /app/ will be added automatically. There are of course other ways to solve the problem, but they are more like crutches)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question