本文主要是介绍tomcat学习(四) 使用nginx反向代理tomcat,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、安装nginx
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install nginx
systemctl start nginx
2、配置一个代理
rpm -ql nginx
找到/etc/nginx/conf.d/default.conf
添加proxy_pass
location / {#root /usr/share/nginx/html;#index index.html index.htm;proxy_pass http://192.168.100.87:8080;}
启动tomcat
systemctl reload nginx
访问http://ip:80 直接跳转至tomcat主页
3、将特定请求代理至tomcat
修改配置文件,将/tomcat的请求代理至tomcat
找到default.conf
location / {root /usr/share/nginx/html;index index.html index.htm;#proxy_pass http://192.168.100.87:8080;}location ^~ /tomcat/ {proxy_pass http://192.168.100.87:8080/;}
执行systemctl reload nginx
访问http:ip:80/tomcat
4、使用nginx做tomcat的负载均衡
找到nginx.conf,添加upstream
upstream tomcat {server 192.168.100.87:8080;server 192.168.100.87:8180;}
找到default.conf,修改
location ^~ /tomcat/ {proxy_pass http://tomcat/; }
systemctl reload nginx
访问http:ip:80/tomcat
这篇关于tomcat学习(四) 使用nginx反向代理tomcat的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!