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 ]
到这里,一个简单的反向代理功能实际上已经完成了。
但是,实战中,肯定还需要做很多的优化。
代理多个:
[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
本文出自 “拔电源的运维空间” 博客,请务必保留此出处http://zhangdj.blog.51cto.com/9210512/1892287
原文:http://zhangdj.blog.51cto.com/9210512/1892287