OPNsense Forum

English Forums => Web Proxy Filtering and Caching => Topic started by: AleksKur on October 12, 2022, 04:55:29 pm

Title: Nginx http reverse proxy with custom location
Post by: AleksKur on October 12, 2022, 04:55:29 pm
Hi!
I have setup nginx with https reverse proxy successfully so I think the bit regarding basic config nuances I can skip in my explanation.
However I want to make some "routing" based on "URL Pattern" (location) and doesn't work correctly for me.
My current setup is that when I come on https://mymain.com it is being reverse proxied to http://myback.com:9000 (running GrayLog web ui). All good here.

But I want to make it working that when coming on https://mymain.com/logs then it should be revproxied to http://myback.com:9000. So I changed
"URL Pattern" under Location to "/logs" with "Match Type: Case Insensitive" (tbh tried all available options for Match type). Now when I am coming to https://mymain.com I am getting 404 which is good. When I am coming on https://mymain.com/logs - I am getting only Title of the web ui and page is just blank. I did some troubleshooting and it appears that next browser should be loading /config.js from the webserver but it is failing - and Nginx error log is showing the following:
Code: [Select]
*4 open() "/usr/local/etc/nginx/html/config.js" failed (2: No such file or directory), client: 123.123.250.14, server: mymain.com, request: "GET /config.js HTTP/2.0", host: "mymain.com", referrer: "https://mymain.com/logs"That log indicates to me that for some reason Nginx is not trying to proxy that request and instead trying to serve config.js from OPNsense box which obviously doesn't exist.

What did I do wrong in my configuration? In my understand all requests towards https://mymain.com/logs/* should be translated/proxied to http://myback.com:9000/* or I am wrong??
Title: Re: Nginx http reverse proxy with custom location
Post by: Fright on October 13, 2022, 04:46:26 pm
Hi
imho you need a rewrite rule for this
like https://fedingo.com/how-to-redirect-subdirectory-to-root-in-nginx/