June 24, 2023 10:05AM
Hello @all,

I have the following challenge. I have a portrange arriving on my nginx server.
Each port should be sent to a remote host on the same port.
The variable $server_port unfortunately does not work.

To be more specific if I specify a port in the nginx-config e.g.: "proxy_pass http://sonartype-nexus:9001/;"
everything works well.
If i use the Variable: "proxy_pass http://sonartype-nexus:$server_port/" it does not work.

Following my config:

server {
listen 9000-9100 ssl;
server_name example.com;

# Allow upload of large files,
# needed if Nexus is going to host large size artifacts
client_max_body_size 20G;

# Add the certificate and key generated earlier
ssl_certificate /etc/nginx/letsenc_cert.pem;
ssl_certificate_key /etc/nginx/letsenc_key.pem;
location / {
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_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_pass http://sonartype-nexus:$server_port/;
}
}

Thanks Frank
Subject Author Posted

reverse proxy port range

conloos June 24, 2023 10:05AM

Re: reverse proxy port range

conloos June 25, 2023 05:57AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 103
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready