1
我正在玩Nginx
,我成功地設置了一個簡單的(現在僅用於HTTP
)反向代理。作爲一個新手,我想知道我需要修改什麼來使這個生產準備就緒。這使我對以下幾個問題: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
}
}
}
任何反饋/指向的方向,將不勝感激。