Score:0

Nginx proxy_pass to http or https different behavior

de flag

Good day! We have a nginx-based proxy with next config:

server {
  server_name  proxy;
  listen 80;
  underscores_in_headers on;
  access_log  /var/log/nginx/access.log  bodylog;

  location / {
    proxy_pass http://X.X.X.X:Y;
  }
}

Backend is an application with first login page access to search after it. So the problem is: When we tune proxy to IP address of backend (proxy_pass http://X.X.X.X:Y) we get that all requests in browser after login in start page go through nginx proxy-server and we can log them to access.log.

But if we want to use here https://address.com for the same application like that

  location / {
    proxy_pass https://address.com;
    resolver 127.0.0.11;
  }

we got that only first load of login page goes through nginx proxy, but all other actions there (login itself, search after it, etc.) go right on domain https://address.com (not through proxy-server), so cannot be logged in nginx-proxy access.log file, but we need this! Is there anyway to change this behavior like with proxy_pass to IP?


Additional info: Application deployed in kube cluster, so when I try to reach it to IP requests go to kube-service for app with type LB and then to app. When hen I try to reach it to DNS name with https request go to nginx-ingress-controller in cluster, then to kube-service for app and then to app

vidarlo avatar
ar flag
What address do you use to access the site through nginx reverse proxy? Is it possible that the application does a redirect or absolute URLs?
Alexey avatar
de flag
To access through proxy I use `http://nginx-IP:80`, or I even tried the same config but with 443 and certs for proxy-server, so that time I used `https://proxy-dns-name.com`. With 443 result the same - using address.com in proxy_pass gets first request to proxy-server goes to application, but in address string of browser address changes to address.com and all next requests in browser to app goes around proxy. I added additional info about app to initial post
vidarlo avatar
ar flag
Go in the developer console of your browser and check exactly what's happening, or use a tool such as `curl` to grab the headers, to see where the redirect is coming from.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.