您的位置:首页 > 运维架构 > 反向代理

nginx反向代理实现

2017-01-16 13:30 381 查看


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/; }
}




写法是需要注意的,跳转有技巧。
http://www.jb51.net/article/78746.htm

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  负载均衡 nginx