nginx反向代理实现


1.部署web页面,方便测试
[root@nginx_116 ~]# salt "*" cmd.run "yum install -y httpd"
--------------------------------------------------------------------------------
[root@server_117 ~]# echo "<html> This is 117 web page! </html>" >/var/www/html/index.html
[root@server_117 ~]# cat /var/www/html/index.html 
<html> This is 117 web page! </html>
[root@server_117 ~]# /etc/init.d/httpd start
httpd:                                                            [  OK  ]
--------------------------------------------------------------------------------
[root@server_118 ~]# echo "<html> This is 118 web page! </html>" >/var/www/html/index.html
[root@server_118 ~]# cat /var/www/html/index.html 
<html> This is 118 web page! </html>
[root@server_118 ~]# /etc/init.d/httpd start
httpd:                                                            [  OK  ]

2.反向代理配置
[root@nginx_116 ~]# yum install -y nginx
[root@nginx_116 ~]# nginx  -v
nginx version: nginx/1.10.2
[root@nginx_116 conf.d]# pwd
/etc/nginx/conf.d
[root@nginx_116 conf.d]# cat proxy.conf 
server{
	listen 80;
	server_name 192.168.111.116;
	location / {
	proxy_pass http://192.168.111.117;
}
}
[root@nginx_116 conf.d]# /etc/init.d/nginx start
Starting nginx:                                            [  OK  ]


到这里,一个简单的反向代理功能实际上已经完成了。
但是,实战中,肯定还需要做很多的优化。比如说:日志文件真实ip的显示等。
--------------------------------------------------------------------------------
代理多个:
[root@nginx_116 conf.d]# cat proxy.conf 
server{
	listen 80;
	server_name 192.168.111.116;
	location  / {
	proxy_pass http://192.168.111.117/;
}
       location /118 {
	proxy_pass http://192.168.111.118/;
}
}

写法是需要注意的,跳转有技巧。



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值