1 year ago
#316424
sonus21
Nginx Multilevel reverse Proxy
Nginx Setup
AKAMAI
| +---> Nginx port 82
| |
-> AWS ELB/ALB -> Nginx Server(Port 80) -> Docker (Nginx Port 81) --|
|
+----> Nginx port 83
Browser sents request on HTTPS but Nginx server running on port 82/83 receiving x-forwarded-proto/scheme as http
instead of https
Nginx Port 80 config
http {
...
server {
...
listen 80;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass "http://127.0.0.1:81";
}
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
}
}
Nginx Port 81 config
server {
listen 81;
location ~ ^/v1/test {
proxy_pass http://127.0.0.1:82;
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
break;
}
location / {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_pass http://127.0.0.1:83;
}
}
Nginx Port 82 Config
server {
...
listen 82;
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
}
Nginx Port 83 Config
server {
...
listen 83;
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
}
Applications running on port 82/83 are rails applications and use Passenger to serve the traffic.
Even we tried setting as below in 82/83 Nginx server configs
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Scheme https;
ruby-on-rails
nginx
passenger
nginx-reverse-proxy
0 Answers
Your Answer