Nginx配置实例之反向代理
目的:使用nginx反向代理,根据访问的路径跳转到不同端口的服务器中,nginx监听端口为9001。
访问http://192.168.17.129:9001/edu/ 跳转到127.0.0.1:8080
访问http://192.168.17.129:9001/vod/ 跳转到127.0.0.1:8081
1、准备工作
(1)准备两个tomcat服务器,一个8080端口,一个8081端口
(2)创建文件夹和测试页面,以edu为例,vod同理:
2、具体配置
(1)配置nginx的config
(2)开放对外访问端口:9001、8080、8081
firewall-cmd --add-port=9001/tcp --permanennt
firewall-cmd --add-port=8080/tcp --permanennt
firewall-cmd --add-port=8081/tcp --permanennt
firewall-cmd --reload
firewall-cmd --list-all
(3)重启nginx
./nginx -s stop
./nginx
3、测试
4、补充location指令规则
location指令用于匹配url,语法如下:
location [ = | ~ | ~* | ^~ ] url {
}