说一说Nginx Proxy配置

2021/6/4 7:27:18

本文主要是介绍说一说Nginx Proxy配置,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

代理模块

ngx_http_proxy_module

代理配置

代理
Syntax:     proxy_pass URL;                #代理的后端服务器URL
Default:    —
Context:    location, if in location, limit_except

头信息
Syntax:     proxy_set_header field value;
Default:    proxy_set_header Host $proxy_host;      #设置真实客户端地址
            proxy_set_header Connection close;
Context:    http, server, location

超时
Syntax:     proxy_connect_timeout time;
Default:    proxy_connect_timeout 60s;              #链接超时
Context:    http, server, location

Syntax:     proxy_read_timeout time;
Default:    proxy_read_timeout 60s;
Context:    http, server, location

Syntax:     proxy_send_timeout time; #nginx进程向fastcgi进程发送request的整个过程的超时时间
Default:    proxy_send_timeout 60s;
Context:    http, server, location

启用nginx proxy代理

虚拟两台nginx服务器192.168.72.145 192.168.72.159

nginx01服务器有网站内容,作为公司网站服务器

nginx02服务器作为代理服务器!

注意:proxy_pass http://填写nginx01服务器地址

nginx proxy 具体配置详解

proxy_pass :真实服务器的地址,可以是ip也可以是域名和url地址
proxy_set_header:重新定义或者添加发往后端服务器的请求头
proxy_set_header X-Real-IP :启用客户端真实地址(否则日志中显示的是代理在访问网站)
proxy_set_header X-Forwarded-For:记录代理地址
proxy_connect_timeout:后端服务器连接的超时时间发起三次握手等候响应超时时间
proxy_send_timeout:后端服务器数据回传时间就是在规定时间之内后端服务器必须传完所有的数据
proxy_read_timeout :nginx接收upstream(上游/真实) server数据超时, 默认60s, 如果连续的60s内没有收到1个字节, 连接关闭。像长连接

使用PC客户端访问nginx02服务器地址

看web应用服务器(nginx01)日志文件


可以看到代理服务器地址,但是客户机请求来源地址没有显示。
注意
关于客户端请求web服务的反向代理和负载均衡在web服务器中的日志文件中显示请求来源ip问题,需详细了解proxy_set_header X-Real-IP、proxy_set_header X-Forwarded-For配置,这里不多赘述。



这篇关于说一说Nginx Proxy配置的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程