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都没有配过的人,东看看,西试试,不容易啊!

  • 相关阅读:
    第五章总结
    第二章总结
    第一章、基础知识总结
    实验 9 根据材料编程
    实验5
    汇编实验4
    实验 3 编程、编译、连接、跟踪
    实验 2 用机器指令和汇编指令编程
    汇编-实验一
    react面试笔录
  • 原文地址:https://www.cnblogs.com/windliu/p/7606673.html
Copyright © 2011-2022 走看看