Welcome! Log In Create A New Profile

Advanced

Re: AW: Nginx multiple upstream with different protocols

February 23, 2017 07:38AM
For a server {} that you want to make both universally compatible with both http port 80 and https port 443 ssl requests.

This was my solution for my own sites.

#inside http block
upstream proxy_web_rack { #port 80 unsecured requests
server 172.16.0.1:80;
}
upstream proxy_web_rack_ssl { #port 443 secured requests
server 172.16.0.1:443;
}
#end http block


#Server block
server {
listen 80;
listen 443 ssl;

location / {

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
if ($scheme = "http") {
proxy_pass $scheme://proxy_web_rack; #if scheme was http send to port 80
}
if ($scheme = "https") {
proxy_pass $scheme://proxy_web_rack_ssl; #if scheme was https send to port 443
}

} #end location

}
#end server block


That way if the recieved request from client is a https secured one proxy_pass will make sure that it goes over port 443 and remains secured.

http://www.networkflare.com/
Subject Author Posted

Nginx multiple upstream with different protocols

Kilian Ries February 22, 2017 10:42AM

AW: Nginx multiple upstream with different protocols

Kilian Ries February 22, 2017 11:10AM

Re: Nginx multiple upstream with different protocols

B.R. via nginx February 22, 2017 12:54PM

AW: Nginx multiple upstream with different protocols

Kilian Ries February 23, 2017 05:40AM

Re: Nginx multiple upstream with different protocols

Andrei February 23, 2017 07:14AM

Re: AW: Nginx multiple upstream with different protocols

c0nw0nk February 23, 2017 07:38AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 247
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready