LNMPA 整合tomcat,实现php+jsp

1、整合nginx+tomcat的原理跟nginx+apache一样。nginx是前端代理,把php请求转发到apache,把jsp请求转发到tomcat

     nginx+apache:php

     nginx+tomcat:jsp

2、配置nginx,进入/usr/local/nginx/conf,增加proxy-pass-jsp.conf,内容为:

        location ~ [^/]\.jsp(/|$)
        {
            proxy_pass http://127.0.0.1:8080;
            include proxy.conf;
        }

3、进入/usr/local/nginx/conf/vhost,找到对应的域名conf,找到include proxy-pass-php.conf;下面添加:

include proxy-pass-jsp.conf;

4、编辑proxy-pass-php.conf,去掉:

        location /
        {
            try_files $uri @apache;
        }

        location @apache
        {
            internal;
            proxy_pass http://127.0.0.1:88;
            include proxy.conf;
        }

5、上面这一步主要为了设置index.jsp为默认页,否则会提示访问错误,但是会导致.htaccess文件失效

6、在nginx.conf和/vhost下对应的conf修改添加:

index index.html index.htm index.php index.jsp;

4、重启nginx

5、配置tomcat,进入/usr/local/tomcat/conf,找到server.xml,找到<host></host>闭合标签,在默认的host下面增加:

      <Host name="你的域名"  appBase="/home/wwwroot"
            unpackWARs="true" autoDeploy="true">
		<Context path="" docBase="你的网站文件夹" debug="0" reloadable="true" />
        <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>

6、进入/tomcat/bin目录,执行./shutdown.sh和./startup.sh,重启tomcat

7、完成。

 


版权声明:本文为gdali原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。