系统相关
首页 > 系统相关> > nginx反向代理实例2

nginx反向代理实例2

作者:互联网

 

一、实现效果

 

使用 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)准备两个 tomcat 服务器,一个 8080 端口,一个 8081 端口

 

修改8081的配置文件:

cd /usr/src/tomcat8081/apache-tomcat-9.0.21/conf

vim server.xml

 

 

 

 

 

 

 

(2)创建文件夹和测试页面

 

 [root@localhost bin]# cd /usr/src/tomcat8080/apache-tomcat-9.0.21/webapps/
[root@localhost webapps]# ls
docs  examples  host-manager  manager  ROOT
[root@localhost webapps]# mkdir edu
[root@localhost webapps]# cd edu/
[root@localhost edu]# vim a.html
[root@localhost edu]# cat a.html
<h1>8080!!</h1>
[root@localhost edu]#

 

 

同理,8081也是如此!

 

[root@localhost edu]# cd /usr/src/tomcat8081/apache-tomcat-9.0.21/webapps/
[root@localhost webapps]# mkdir vod
[root@localhost webapps]# cd vod/
[root@localhost vod]# vim a.html
[root@localhost vod]# cat a.html
<h1>8081!!</h1>
[root@localhost vod]#

 

三、具体配置

 

(1)找到 nginx 配置文件,进行反向代理配置

[root@localhost vod]# cd /usr/local/nginx/conf/
[root@localhost conf]# vim nginx.conf
[root@localhost conf]#

 

 

 

四、最终测试



 

 

 

标签:vod,webapps,cd,nginx,实例,反向,edu,root,localhost
来源: https://www.cnblogs.com/zypdbk/p/16607247.html