Nginx + Tomcat 有关SSI 的那些事儿

文章目录[隐藏]

  • < %=lgtime%>
  • 在工作中使用到SSI,对于静态页面由Nginx处理SSI是没有问题。对于jsp 文件里面的SSI怎么办呢?我们不想开启Tomcat的 SSI功能,我们希望SSI 的解析交给Nginx来完成,Tomcat 只处理应用。

    下面的文章用实例说明这是可行的。

    文章节选择 《Netkiller Web 手札》 Tomcat 篇

    3.2.6.5. Proxy 与 SSI

    背景:nginx + tomcat 模式,nginx 开启 SSI , Tomcat 动态页面中输出 SSI 标签

    # cat  /etc/nginx/conf.d/www.netkiller.cn.conf
    server {
        listen       80;
        server_name  www.netkiller.cn;
    
        charset utf-8;
        access_log  /var/log/nginx/www.netkiller.cn.access.log;
    
        location / {
            #index  index.html index.htm;
    		proxy_pass http://127.0.0.1:8080;
            proxy_set_header    Host    $host;
            proxy_set_header    X-Real-IP   $remote_addr;
            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    
        #error_page  404              /404.html;
    
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    }
    

    test.jsp 文件

    < %@ page language="java" import="java.util.*,java.text.SimpleDateFormat" pageEncoding="UTF-8"%>
    < !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    	
    	show time
    
    
    < %
    
    	Date date=new Date();
        SimpleDateFormat ss=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String lgtime=ss.format(date);
    %>
    	

    < %=lgtime%>

    测试并查看源码,你会看到SSI标签

    
    	
    

    解决方案

    location / {
            ssi on;
            proxy_set_header Accept-Encoding "";
            proxy_pass http://127.0.0.1:8080;
            proxy_set_header    Host    $host;
            proxy_set_header    X-Real-IP   $remote_addr;
            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    

    原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/tech/aiops/57542.html

    (0)
    上一篇 2021年8月9日 08:41
    下一篇 2021年8月9日 08:41

    相关推荐

    发表回复

    登录后才能评论