NGINX Reverse Proxy redirecting instead of proxying
Asked Answered
S

1

7

i have a NGINX server running as a reverse proxy. Proxy works for windows hosts however i have a owncloud server and the proxy will instead re wright the url to the internal host name or IP address. ex(I type cloud.example.com and my url bar will change to 10.1.1.19 which is unresolvable over wan

i have checked DNS records and made sure NGINX can resolve host name. also tried just forwarding http traffic to cloud server to make sure using domain name was not the issue.

server {
  listen 80;
  listen [::]:80;

  server_name example.com;

  location / {
      proxy_pass http://10.1.1.16:80/;
  }
}

server {
  listen 80;
  listen [::]:80;

  server_name cloud.example.com;

  location / {
      proxy_pass http://10.1.1.19:80/;
  }
}

server {
  listen 80;
  listen [::]:80;

  server_name remote.example.com;

  location / {
      proxy_pass http://10.1.1.17:80/;
  }
}

i just need NGINX to run as a proxy for "cloud.example.com" instead of rewriting URL

Savoirvivre answered 24/12, 2018 at 18:7 Comment(5)
can you try removing / from end of URL in proxy_passThematic
did not work. it is still redirecting to the internal address new code below server { listen 80; listen [::]:80; server_name cloud.example.com; location / { proxy_pass 10.1.1.19:80; } }Savoirvivre
Try creating different files for each URL and put them in sites-enabled folder, run nginx -t reload after that. Remove IPV6 listen [::]:80; from conf. Let me know about result then I will share some working conf file with youThematic
so this actually broke the more of the sites. however in putting everything back i did see it is only the Linux hosts that are redirecting instead of proxying i added cockpit just to test this and it does the same however i throw up the windows IIS page give it a random port and it works fine. is there a config issue with linux i am overlooking?Savoirvivre
I'm a linux noob so i stood up a "desktop" version so i had a UI to work with did exactly as you said. this time it didnt break the windows hosts but any of the linux hosts rewright the url to the internal IP of the server.Savoirvivre
I
0

I found a partial answer to this -- Why is my Nginx reverse proxy doing a 301 redirect instead of proxying?.

For me, it kept nginx from changing the hostname (i.e. from good-domain.com to 10.1.5.5:8080), but there doesn't appear to be a way to stop nginx from appending the port to the client's request URL.

So, in using the answer referenced above, I was able to go from http://10.1.5.5:8080 to http://good-domain:8080. It's still not where I want to be, but it definitely gets me closer.

Isabelleisac answered 4/3, 2021 at 16:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.