Welcome! Log In Create A New Profile

Advanced

Reverse Proxy URL Without Base URL

Posted by bzowk 
Reverse Proxy URL Without Base URL
November 06, 2019 10:10AM
Hey Guys -

I use Nginx in my home lab as a reverse proxy for multiple locally hosted pages as well as add an SSL layer. Although I've successfully been able to configure most of my pages in the past, I'm having trouble with this one. Below are details followed by what I've tried with results…

Details
- Trying to forward URL which is hosted on port 80 of a LAN system - "http://prtgsvr" (prtgsvr is a hostname)
- Wish to rewrite it to https://mydomain.com/prtg
- Application does not offer option to configure a base URL
- Browsing to "http://prtgsvr" simply goes to "http://prtgsvr/index.html"

Attempt #1
location /prtg {
rewrite /prtg(.*) /$1 break;
proxy_pass http://prtgsvr;
proxy_set_header Host $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_http_version 1.1;
proxy_set_header Connection "";

Result #1
Page tries to load until it times out with 404 which then shows it was trying to go to "mydomain.com/index.html"

Attempt #2
location /prtg/ {
proxy_pass http://prtgsvr/;
proxy_redirect http://prtgsvr/ http://mydomain.com/prtg/;
proxy_set_header Host $host;
proxy_set_header Referer $http_referer;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}

Result #2
Redirected to "mydomain.com/index.html" and displayed 404 since I do not have an index.html in the root. I also tried this using "https" on the proxy_redirect line with the same results.

If it Helps...
When searching for a solution, I did find the below config which someone used with the same application, however; it doesn't redirect it to a URL Base:

upstream prtgaero-rs {
server prtgaero.palmbeach.k12.fl.us;
keepalive 32;
}
server {
listen 443 ssl;
server_name prtgaero01.palmbeach.k12.fl.us
ssl on;
ssl_certificate /etc/nginx/ssl/prtgaero01.crt;
ssl_certificate_key /etc/nginx/ssl/prtgaero01.pem;
location / {
proxy_pass http://prtgaero-rs;
proxy_set_header Host $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_http_version 1.1;
proxy_set_header Connection "";
}
}

Thanks Guys



Edited 1 time(s). Last edit at 11/06/2019 10:10AM by bzowk.
Re: Reverse Proxy URL Without Base URL
November 12, 2019 03:40PM
Hi there - I think we're trying to do the same thing. I've posted my problem here - https://stackoverflow.com/questions/58775388/nginx-proxy-pass-from-subfolder-destination-files-404ing-rewrite-rule-req/58805029

Have you head any luck solving this?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 139
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready