Nginx 反向代理:使用 1 台服务器代理 2 台不同的服务器
Nginx Reverse Proxy: Proxying 2 different servers with using 1 server
我有 1 个 Nginx 代理服务器,但我有 2 个不同的普通服务器。我想仅使用 1 个 nginx 代理服务器来代理此普通服务器。它可能很简单,但我找不到它。
这是我在 /etc/nginx/sites-available/default 中的代码(使用此代码我只能代理 1 个服务器):
server {
listen 80;
#server_name 1ndwebsite.com;
root /usr/share/nginx/html;
location / {
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass https://122.122.122.123;
}
}
我在第二台服务器上试过了,但没用。
server {
listen 80;
#server_name 1ndwebsite.com;
root /usr/share/nginx/html;
location / {
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass https://122.122.122.123;
}
}
server {
listen 80;
#server_name 2ndwebsite.com;
root /usr/share/nginx/html;
location / {
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass https://211.211.211.213;
}
}
很有趣,但我通过在 location
标签后添加 include /etc/nginx/proxy_params;
解决了这个问题。
我有 1 个 Nginx 代理服务器,但我有 2 个不同的普通服务器。我想仅使用 1 个 nginx 代理服务器来代理此普通服务器。它可能很简单,但我找不到它。
这是我在 /etc/nginx/sites-available/default 中的代码(使用此代码我只能代理 1 个服务器):
server {
listen 80;
#server_name 1ndwebsite.com;
root /usr/share/nginx/html;
location / {
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass https://122.122.122.123;
}
}
我在第二台服务器上试过了,但没用。
server {
listen 80;
#server_name 1ndwebsite.com;
root /usr/share/nginx/html;
location / {
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass https://122.122.122.123;
}
}
server {
listen 80;
#server_name 2ndwebsite.com;
root /usr/share/nginx/html;
location / {
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass https://211.211.211.213;
}
}
很有趣,但我通过在 location
标签后添加 include /etc/nginx/proxy_params;
解决了这个问题。