CentOS7 nginx+tomcat实现代理访问java web项目让项目支持jsp和php
Posted James wang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS7 nginx+tomcat实现代理访问java web项目让项目支持jsp和php相关的知识,希望对你有一定的参考价值。
首先配置:nginx
# cd /etc/nginx/conf.d/ # cp default.conf tomcat.conf # nano tomcat.conf
请在tomcat.conf里输入:
server { listen 80; server_name mydomain.com; index index.jsp; root /usr/share/nginx/html/h5; location / { proxy_pass http://mydomain.com:8080; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
这里请注意:mydomain.com是你的域名,/usr/share/nginx/html/h5是你的项目路径,要与下面的tomcat对应起来.
其次,修改Server.xml
# nano /usr/local/tomcat/conf/server.xml
请修改如下:
<Host name="mydomain.com" appBase="/usr/share/nginx/html/h5" unpackWARs="true" autoDeploy="true"> <Context path="" docBase="/usr/share/nginx/html/h5" debug="0" reloadable="false" crossContext="tr$ <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host>