有一个需求:

两个域名指向同一个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都没有配过的人,东看看,西试试,不容易啊!

posted on 2017-09-28 14:51  j.liu windliu  阅读(622)  评论(0编辑  收藏  举报