r/nginx

▲ 3 r/nginx+1 crossposts

How to pick up values (args) from NGINX Reverse Proxy

I'm probably missing something obvious here, but how do I access values which have been transmitted by a client to NGINX Reverse Proxy?

In my setup, if I use NGINX as a simple HTTP server, my PHP scripts inherit any arguments in the $_POST global variable and I can issue responses just fine.

However, for business reasons I need to run my PHP script as a service, using "socket_create" to accept connections.

This works fine (mostly). The remote client communicates with the NGINX Reverse Proxy, which talks my PHP script (running as a service) and I can return data to the Proxy Server, which then transmits back to the client. All tested and working.

What I can't seem to do (no doubt due to my ignorance) is access the data being sent from the remote client to the proxy server.
The data I receive looks like this...

>GET / HTTP/1.0
Host: 192.168.56.xxx
X-Real-IP: 192.168.56.xxx
X-Forwarded-For: 192.168.56.xxx
X-Forwarded-Proto: http
Connection: close
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:147.0) Gecko/20100101 Firefox/147.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.9
Accept-Encoding: gzip, deflate
Cookie: MY_SESSION=8c1b0n9nb82o68fuiiknkui64e; PHPSESSID=a5e0dug6437a7ijv13rq33racp
Upgrade-Insecure-Requests: 1
Priority: u=0, i

...but no data from the client!

I'm sure it's obvious, but what am I missing?

EDIT: PROXY STUFF FROM sites-available

>location / {
# PROXY STUFF, FROM THE INTERWEBS
proxy_pass http://127.0.0.1:5010;
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;
}

SOLVED

Thanks to the respondents below. Food for thought.

What was happening was that I was running my "script as a service" in my editor and just using the "run" option. It's never caused problems before.

However, I've now tried calling from the CLI and the args have miraculously appeared!

I've tested this a few times and the behaviour appears consistent. The header that I previously posted was a result of using the "run" command. The real thing is the same but with the data I want appended (can't show it).

I blame the developers at Geany. This had absolutely nothing to do with my lack of lateral thinking.

reddit.com
u/Initiative_Least — 8 days ago
▲ 3 r/nginx

I've been using Nginx for a long time to reverse proxy a number of local servers.

Yesterday my Home Assistant server configuration stopped working while using the local FQDN with a 502 Bad Gateway. I changed to the IP in Nginx, and it started to work again.

I use Pihole for local DNS. Nginx, Pihole and HA are on Proxmox VMs.

I SSHed into the Nginx server. nslookup resolved the correct IP address for HA. I can ping both the FQDN and IP for HA from Nginx server. I tried Curl to both the FQDN and IP... and both work.

So, the Nginx server can see the home assistant server, but the reverse proxy only works using the IP address. I guess I'm ok with that as I don't expect to change the IP address any time soon, but why would this suddenly stop working?

I did change out my router and firewall (EdgrouterX to Unfi Gateway), but the server can still see the HA server. It seemed fine for a few days... and now it fails on the FQDN. Does Nginx use a different port/method for DNS than the underlying Linux server?

reddit.com
u/sandiegosteves — 14 days ago