nginx反向代理实例2
2022/8/21 5:25:11
本文主要是介绍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)创建文件夹和测试页面
[[email protected] bin]# cd /usr/src/tomcat8080/apache-tomcat-9.0.21/webapps/
[[email protected] webapps]# ls
docs examples host-manager manager ROOT
[[email protected] webapps]# mkdir edu
[[email protected] webapps]# cd edu/
[[email protected] edu]# vim a.html
[[email protected] edu]# cat a.html
<h1>8080!!</h1>
[[email protected] edu]#
同理,8081也是如此!
[[email protected] edu]# cd /usr/src/tomcat8081/apache-tomcat-9.0.21/webapps/
[[email protected] webapps]# mkdir vod
[[email protected] webapps]# cd vod/
[[email protected] vod]# vim a.html
[[email protected] vod]# cat a.html
<h1>8081!!</h1>
[[email protected] vod]#
三、具体配置
(1)找到 nginx 配置文件,进行反向代理配置
[[email protected] vod]# cd /usr/local/nginx/conf/
[[email protected] conf]# vim nginx.conf
[[email protected] conf]#
四、最终测试
这篇关于nginx反向代理实例2的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-29fail2ban nginx
- 2024-03-18install nginx proxy manager
- 2024-01-2444从零开始用Rust编写nginx,命令行参数的设计与解析及说明
- 2024-01-22比Nginx更好用的Gateway!
- 2024-01-17nginx daemon off
- 2023-12-30Nginx Vhost Traffic Status 是什么意思-icode9专业技术文章分享
- 2023-12-26使用nginx搭建creates.io镜像(稀疏索引)
- 2023-11-18centos7编译安装Nginx教程。
- 2023-11-02nginx启动命令和停止命令
- 2023-10-25Centos7系统Nginx负载均衡如何安装和配置?