zoukankan      html  css  js  c++  java
  • [菜鸟弄nginx]nginx ---- 同一个server下根据host 配置不同的error_page页

    有一个需求:

    两个域名指向同一个nignx,不同的域名404跳转页面不同。如www.y.com跳到www.y.com/error.html ,www.j.com跳到www.j.com/errorxxx.html

    配置如下:

    server {
    	listen       80;
    	server_name  www.j.com www.y.com s.jd.com s.y.com;
    	
    	access_log  logs/www.j.com/access.log main;
    	
    	error_page 404 500 502 503 504   @fallback; //跳转到@fallback逻辑
    
    	location / {
    		proxy_pass http://localhost:8080/;
    		proxy_intercept_errors on;

         if ($host ~* s.j.com){      //不同的host,重定向规则不同
                rewrite ^/(.*)$ http://www.j.com permanent;
             }
            if ($host ~* s.y){
             rewrite ^/(.*)$ http://www.y.com permanent;
            }

    	}
    	
    	location = /j_error.html {
    		root   /html;
    		index  50x.html;
    	}
    	
    	location @fallback {
    	   if ($host ~* www.y.com){    //如果域名包含www.y.com
    	      return   http://www.y.com/errorxxx.html;
    	   } 
    	    return  http://www.j.com/error.html;   //其他情况
    	}
    	
    }
    

     初步测试成功,作为连server都没有配过的人,东看看,西试试,不容易啊!

  • 相关阅读:
    洛谷 P1282 多米诺骨牌
    【2017杭二联考】穿越矩形
    【2017杭二联考】 图的有向环
    树状数组
    Test2014-3-1 魅力值比较
    NOI2007 货币兑换
    POI2001 金矿
    太空飞行计划问题
    Genotype&&陨石的秘密
    usaco 土地并购 && hdu 玩具装箱
  • 原文地址:https://www.cnblogs.com/windliu/p/7606673.html
Copyright © 2011-2022 走看看