如何在tomcat前部署一个nginx

时间:2024-01-07 13:37:26

在tomcat应用已经发布后,如何在tomcat前部署一个nginx,可以正常访问jsp,静态资源(html,css,js)

这里tomcat的端口号是8888

 upstream   morris {
server 127.0.0.1:8888;
} server {
listen 80;
server_name tooth.xxxx.com;
root /usr/share/nginx/html; # Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf; #都没有匹配就走这个映射
location / {
proxy_pass http://morris;
} #location /tooth_resoure/ {
# root /mydata/toothapp;
#} #这里是对jsp的转发
location ~ \.(jsp|jspx|do|action)?$
{
#=============tomcat的资源位置============
root /mydata/toothapp/tooth_resoure;
index index.jsp index.jspx index.do;
#==========Nginx提供的代理============
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#=== 如果遇到.jsp .jspx .do .action 的请求就进入该服务器(tomcat)===
proxy_pass http://127.0.0.1:8888;
} #这里是对静态资源的转发,ip地址写服务器的真实地址
location ~ .*\.(html|htm|ico|png|jpg|jpeg|js|css|bmp)$ {
proxy_pass http://xx.xx.xx.xx:8888;
} }

参考: https://www.cnblogs.com/jalja/p/6117523.html

https://blog.csdn.net/cxm19881208/article/details/65441865