版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
为什么需要为tomcat配置nginx反向代理?
1.当服务器上同时拥有nginx与tomcat时,tomcat修改8080端口为80会冲突
2.tomcat不更改监听端口8080即可使用nginx的80端口
3.Nginx对于静态的请求速度上要优于Tomcat,Tomcat不擅长做高并发的静态文件请求处理
以上一篇文章搭建的个人博客网站为例,配置nginx代理tomcat
添加nginx虚拟主机配置文件:
[root@linux ~]# vi /etc/nginx/conf.d/z.blog.com
添加如下内容:
erver {
server_name z.blog.com;
location /
{
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
验证配置并重载:
[root@linux ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@linux ~]# nginx -s reload
修改Windows系统C:\Windows\System32\drivers\etc\hosts文件:
#将自定义的域名映射到服务器地址
在浏览器访问:
#成功,在tomcat下部署的个人博客网站已经显示,访问不用再加上8080端口