我需要nginx来重定向请求而不需要代理。 我有这个nginx.config文件:
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
upstream web_rack {
server ip_address_1;
server ip_address_2;
server ip_address_3;
server ip_address_4;
}
server{
listen 80;
location / {
proxy_pass http://web_rack;
rewrite ^ http://<variable>$request_uri permanent;
}
}
}
如何获取从nginx获取重定向请求的服务器IP地址。我想存在一些存储这个IP地址的“变量”,但我不知道如何获得它。
答案 0 :(得分:0)
感谢大家的帮助)
我用该配置解决了我的问题:
http{
include /etc/nginx/mime.types;
default_type application/octet-stream;
upstream web_rack {
server localhost:8080;
server localhost:8081;
}
server{
listen 80;
location / {
proxy_pass http://web_rack;
}
}
server{
listen localhost:8080;
location / {
return 302 https://ip_address_1$request_uri;
}
}
server{
listen localhost:8081;
location / {
return 302 https://ip_address_2$request_uri;
}
}
}