以下是 Nginx 反向代理設定檔範例:
server {
listen 80;
server_name www.example.com;
location / {
proxy_pass http://backend:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
此設定檔將在 port 80 監聽 HTTP 請求,並將請求轉發到 port 8080 上的 backend server。請求的 Host 和 X-Forwarded-For 標頭將被保留。
以下是一些其他常見的 Nginx 反向代理設定檔範例:
server {
listen 80;
server_name www.example.com;
location / {
proxy_pass http://backend:8081;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 80;
server_name www.example.com;
location / {
proxy_pass http://192.168.1.100:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
- 使用 SSL 將請求轉發到 backend server:
server {
listen 443 ssl;
server_name www.example.com;
ssl_certificate /etc/ssl/certs/example.com.crt;
ssl_certificate_key /etc/ssl/private/example.com.key;
location / {
proxy_pass https://backend:443;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
希望這對你有幫助!