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 &quot;%r&quot; %s %b" />
    </Host>

 

学习交流群:364976091
上一篇:Kotlin 和 Java EE(Part 3):让 Kotlin 符合使用习惯


下一篇:如何实现IIS 7.0对非HTTP协议的支持