14

tomcat 配置nginx 反向代理

 2 years ago
source link: https://blog.51cto.com/u_15148274/5454948
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

tomcat 配置nginx 反向代理

原创

解释为什么要为Tomcat配置反向代理?

1、如果同一台机器又有Nginx又有Tomcat,则会产生端口冲突。
2、为了访问时不需要输入端口后缀所以我们需要把8080端口变成80端口。
3、Nginx对于静态的请求速度上要优于Tomcat,Tomcat不擅长做高并发的静态文件请求处理

所以需要配置nginx反向代理。

配置

首先到nginx配置文件的目录下 配置一个虚拟主机的配置文件

cd /etc/nginx/conf.d/ (以我自己目录为例)
vim zrlog.cc.conf      (自定义个文件并加入下列 配置内容)

server {

	server_name zrlog.cc;
	
        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;
        }
}
tomcat 配置nginx 反向代理_tomcat
重载nginx配置文件
nginx -t
nginx -s reload
然后在Windows上指定hosts
hosts路径
C:\Windows\System32\drivers\etc
tomcat 配置nginx 反向代理_zrlog_02

然后网页访问验证

tomcat 配置nginx 反向代理_nginx_03

可以点管理登入进去修改信息 然后就可以玩起来了

ps: tomcat 配置安装zrlog 的参考链接: https://blog.51cto.com/u_15148274/5450783


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK