I
I
Ilya Evseev2015-06-17 04:09:54
Nginx
Ilya Evseev, 2015-06-17 04:09:54

Can Nginx take the port for proxy_pass from the request?

Nginx works like a normal proxy. Receives requests of the following form:
GET http://example.org/page.html
/etc/nginx/conf.d/proxy.conf:

server {
        listen 3128;
        resolver 8.8.8.8;
        server_name _;
        location / {
                proxy_pass $scheme://$host$uri;
        }
}

The problem is that the request may contain a non-standard port (for example, GET example.org :81 /page.html), and Nginx will still send it to port 80.
If you write "proxy_pass $request;", then Nginx will respond to any requests ( with or without a port) starts swearing in the logs:
invalid URL prefix in "GET http://example.org/page.html HTTP/1.1"

Is it possible to teach Nginx to connect to the port specified in the request?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question