J
J
John_Wick2016-08-17 12:21:41
Nginx
John_Wick, 2016-08-17 12:21:41

Correct config NGNIX reserve proxy 1 ip and several virtual web servers?

There are several web servers on NGNIX. There is 1 static ip. In order to use port 80 on all virtual machines, ngnix was raised on the host machine in order to configure it as a reserve proxy. Will the following config work?
server {
listen 80;
server_name example1.com;
server_name_in_redirect on;
location / {
proxy_pass http://192.168.0.1:80; # virtualka1 ip
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 80;
server_name example2.com;
server_name_in_redirect on;
location / {
proxy_pass http://192.168.0.2:80; # virtualka2 ip
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
How to proxy port 443 for ssl? Is it possible to add the port separated by commas so that it would be something like this?
server {
listen 80,443;
server_name example1.com;
server_name_in_redirect on;
location / {
proxy_pass http://192.168.0.1:80; # virtualka1 ip
proxy_pass http://192.168.0.1:443; # virtualka1 ip
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
or does it need to create its own section for each port like here?
server {
listen 443;
server_name example1.com;
server_name_in_redirect on;
location / {
proxy_pass http://192.168.0.1:443; # virtual machine ip1
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Where can I find examples of working configs for reserve proxy?
I also saw this config option with dns and alias/subdomain
server {
listen 192.168.1.1:80;
listen 8.8.8.8:80;
server_name www.examle.com
#access section
allow all;
#deny all;
location / {
proxy_pass http://192.168.1.2:8080;
proxy_store on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
manimi, 2018-02-28
@manimi

Use upstream
https://nginx.ru/en/docs/http/ngx_http_upstream_mo...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question