我正在尝试将Nginx配置为LAN上多个服务器的反向代理.他们应该在我的WAN上使用不同的子域.我的配置如下所示:
@ReverseProxy:/etc/Nginx/sites-enabled$cat reverseproxy
server {
server_name DOMAIN.eu;
# app1 reverse proxy follow
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://10.0.2.5:80;
}
server {
server_name Subdomain.domain.eu;
# app2 reverse proxy settings follow
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://10.0.2.33:80;
}
但我收到这个错误,无法进一步……
@ReverseProxy:/etc/Nginx/sites-enabled$Nginx -t
Nginx: [alert] could not open error log file: open() "/var/log/Nginx/error.log" Failed (13: Permission denied)
2009/01/04 12:22:13 [warn] 1302#0: the "user" directive makes sense only if the master process runs with super-user privileges,ignored in /etc/Nginx/Nginx.conf:1
2009/01/04 12:22:13 [emerg] 1302#0: "proxy_pass" directive is not allowed here in /etc/Nginx/sites-enabled/reverseproxy:8
最佳答案
您的问题是您在服务器块内使用proxy_pass,这是不允许的.尝试使用:
server {
server_name Subdomain.domain.eu;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://10.0.2.33:80;
}
}
在您的服务器块内.正如nginx documentation所说,无法在服务器级别设置代理选项.