nginx代理
正向代理,(内部上网)
反向代理,用于公司集群架构中

正向与反向代理的区别
区别在于形式上服务的"对象"不一样
正向代理代理的对象是客户端,为客户端服务 PC电脑
反向代理代理的对象是服务端,为服务端服务 服务器
nginxfd01.png
|反向代理模式|Nginx配置模块|
|-------|-------|
|http、websocket、https|ngx_http_proxy_module|
|fastcgi (php)|ngx_http_fastcgi_module|
|uwsgi (python)|ngx_http_uwsgi_module|
|grpc (go)|ngx_http_v2_module|

配置后端的web

[root@web01 conf.d]# cat blog.oldboy.com.conf 
server {
	listen 80;
	server_name blog.oldboy.com;
	root /web;
	location / {
		index index.php index.html;
	}
}
[root@web01 conf.d]# mkdir /web
[root@web01 conf.d]# echo "Web01....." > /web/index.html
[root@web01 conf.d]# nginx -t
sysnginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web01 conf.d]# systemctl restart nginx

nginxfd02.png

配置nginx代理配置

[root@lb01 conf.d]# cat proxy_web.conf
server {
	listen 80;
	server_name web.oldboy.com;
	location / {
		proxy_pass http://10.0.0.56:80;
		proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   # 记录客户端真实IP地址(生产必加的参数)
	}
}

在web上面看日志就能看客户端访问IP地址
nginxfd03.png

文章作者: 鲜花的主人
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 爱吃可爱多
Nginx Nginx
喜欢就支持一下吧
打赏
微信 微信
支付宝 支付宝