UJCMS配置nginx反向代理

2022-09-23 10:34 阅读

配置文件

修改配置文件

vim /etc/nginx/nginx.conf

整合tomcat

server {
  # 监听端口
  listen       80;
  # 域名。可使用下划线,代表所有域名
  #server_name  _;
  server_name  www.ujcms.com;
  # 程序目录
  # windows目录
  #root         D:/tomcat/webapps/ROOT
  # 如使用部署路径,则需要加上部署路径
  #root         D:/tomcat/webapps/ROOT/mycontenxtpath
  root         /data/tomcat/webapps/ROOT;
  index        index.html index.htm index.shtml;

  # 处理规则
  # 如使用部署路径,则可加上部署路径
  #location /mycontextpath {
  location / {
    # 如果uri地址对应文件或目录不存在,则使用代理转发到tomcat
    # try_files  $uri $uri/index.html $uri/index.htm @proxypass;
    # 查找目录可以利用nginx将文件重定向至目录,如访问 /foo,目录存在的话,会重定向至 /foo/
    try_files  $uri $uri/ @proxypass;
  }

  # 如使用 try_files  $uri $uri/ @proxypass; 则必须加上这项,否则可能出现首页无法访问的情况
  # 如使用了部署路径,则该项可以删除
  location = / {
    try_files  /index.html @proxypass;
  }


  location @proxypass {
    # 代理至tomcat,tomcat需监听8080端口
    proxy_pass http://localhost:8080;
  }

  # 禁止访问/WEB-INF/目录下文件
  location /WEB-INF/ {
    deny  all;
  }
}
咨询
交流群
电话