我正在玩Nginx
,我成功地设置了一个简单的(HTTP
仅限现在)反向代理。作为一个新手,我想知道我需要修改什么来使这个生产准备好。这导致我提出以下问题:
- 有没有办法统一
proxy_set_header
指令,这样我就不需要为每个虚拟主机重复自己? - 除了,和之外
X-Forwarded-Proto
,我是否遗漏了任何其他重要的主机头修改?X-Url-Scheme
X-Forwarded-For
Host
nginx.conf
:
worker_processes 1;
events {
worker_connections 1024;
}
http {
sendfile on;
gzip on;
# skip log_format/access_log
server {
listen 80;
server_name server1.company.com;
location / {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Url-Scheme $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://server1; # IP or FQDN would be better here
}
}
server {
listen 80;
server_name server2.company.com;
location / {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Url-Scheme $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://server2; # IP or FQDN would be better here
}
}
}
任何反馈/指向一个方向将不胜感激。