Mobile wallpaper 1Mobile wallpaper 2Mobile wallpaper 3Mobile wallpaper 4Mobile wallpaper 5Mobile wallpaper 6
181 字
1 分钟
Nginx 反向代理配置指南
2022-09-22
统计加载中...

本文详细介绍 Nginx 反向代理的配置方法及实际应用场景。

反向代理概念#

{% note primary %}

代理类型对比#

  • 正向代理: 代理客户端访问服务器
  • 反向代理: 代理服务器接收请求

配置示例#

{% tabs nginx-config %}

upstream web1 {
server 192.168.0.222 weight=1;
}
server {
listen 80;
server_name www.example.com;
location / {
proxy_pass http://web1;
proxy_set_header X-Real-IP $remote_addr;
}
}
upstream web_cluster {
server 192.168.0.1 weight=1;
server 192.168.0.2 weight=1;
ip_hash;
}

实用配置#

关键配置项#

  • proxy_set_header: 设置请求头
  • proxy_connect_timeout: 连接超时
  • proxy_read_timeout: 读取超时
  • proxy_redirect: 重定向设置

{% folding cyan, 获取真实IP配置 %}

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;

{% endfolding %}

相关工具#

Nginx官网::https://nginx.org/::fa-solid fa-server %}

Nginx 反向代理配置指南
https://blog.jisuk.top/posts/nginx反向代理/
作者
不鹤Buhe
发布于
2022-09-22
许可协议
CC BY-NC-SA 4.0

部分信息可能已经过时

封面
Sample Song
Sample Artist
封面
Sample Song
Sample Artist
0:00 / 0:00