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

转载于:https://www.cnblogs.com/windliu/p/7606673.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值