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  ]



到這裏,一個簡單的反向代理功能實際上已經完成了。html

可是,實戰中,確定還須要作不少的優化。python


代理多個:nginx

[root@nginx_116 conf.d]# cat proxy.confweb

server{ide

listen 80;測試

server_name 192.168.111.116;優化

location  / {spa

proxy_pass http://192.168.111.117/;.net

}代理

location /118 {

proxy_pass http://192.168.111.118/;

}

}



寫法是須要注意的,跳轉有技巧。

http://www.jb51.net/article/78746.htm

相關文章
相關標籤/搜索