Nginx-http反向代理-配置示例
1、环境准备
1.1、主机清单
192.168.10.4 nginx主机 192.168.10.5 web01
1.2、反向代理架构图
user -> nginx -> web01
1.3、web01准备
1.3.1、准备测试代码
mkdir /opt/web01 echo "web-01" >/opt/web01/index.html
1.3.2、配置nginx
cat >/etc/nginx/conf.d/web01.cyc.com.conf<<'EOF' server{ listen 8080; server_name web01.cyc.com; location / { root /opt/web01; index index.html; } } EOF
1.3.3、重新加载nginx并且测试
systemctl restart nginx
~]# curl localhost:8080 web-01
2、配置反向代理nginx
2.1、配置常用的代理请求头参数
cat >/etc/nginx/proxy_params<<'EOF' proxy_http_version 1.1; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 30s; proxy_send_timeout 60s; proxy_read_timeout 60s; proxy_buffering on; proxy_buffer_size 64k; proxy_buffers 4 64k; EOF # 参考文章:https://www.cnblogs.com/ygbh/p/17365450.html#_label5
2.2、配置nginx
cat >/etc/nginx/conf.d/proxy_web01.cyc.com.conf<<'EOF' server{ listen 80; server_name web01.cyc.com; location / { proxy_pass http://192.168.10.5:8080; include proxy_params; } } EOF
2.3、重新加载nginx
systemctl reload nginx
2.4、配置hosts
echo "192.168.10.4 web01.cyc.com" >>/etc/hosts
2.5、测试访问
[root@nfs ~]# curl web01.cyc.com web-01
2.6、完成配置
配置反理代理成功
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了