nginx 的error_page對付同一個(gè)http狀態(tài)碼,莫斯科服務(wù)器 新加坡vps,只能執(zhí)行一次,第二次就不會(huì)再執(zhí)行了(初認(rèn)識(shí)有錯(cuò)誤)。
譬喻:403狀態(tài)
下面這段代碼,假如會(huì)見呈現(xiàn)403,會(huì)跳到retry段,在沒有,就會(huì)直接呈現(xiàn)403,而不會(huì)跳到http://www.server110.com/download/error403.html。
location @retry { #return 409; root /data1/; index index.html index.htm; error_page 403 http://www.server110.com/download/error403.html; } location / { root /data/; index index.html index.htm; error_page 403 = @retry ; error_page 404 = http://www.server110.com; } |
本日有做了個(gè)測試,假如利用lua把狀態(tài)碼改成此外,再利用error_page,會(huì)不會(huì)可以呢?
location @retry { # return 409; root /data/www; index index.html index.htm index.php; content_by_lua ' return ngx.exit(410); '; error_page 404 = http://www.baidu.com; error_page 403 = http://danhuaer.com/; error_page 410 = http://news.17173.com/game/yzdzh.shtml; } location / { root /data/www/www; index index.html index.htm index.php; error_page 403 = @retry; error_page 404 = http://www.server110.com; } |
我把/data/www/www目次下的index.html刪除了,匹配到/,會(huì)呈現(xiàn)403,再跳到retry中,利用lua返回401的狀態(tài)碼,看error_page是否能跳轉(zhuǎn)到http://news.17173.com/game/yzdzh.shtml?
驗(yàn)證:
看來error_page在一次請求中,只能利用一次,無關(guān)狀態(tài)碼是否溝通。
不能利用error_page,怎么才氣把nginx的狀態(tài)碼不讓用戶看的,而是可以直接跳到指定的頁面?
雖然是利用lua就行跳轉(zhuǎn)了
location @retry { # return 409; root /data/www; index index.html index.htm index.php; content_by_lua ' --return ngx.exit(410); ngx.redirect("http://jd.com", 302); '; error_page 404 = http://www.baidu.com; error_page 403 = http://danhuaer.com/; error_page 410 = http://news.17173.com/game/yzdzh.shtml; } location / { root /data/www/www; index index.html index.htm index.php; error_page 403 = @retry; error_page 404 = http://dl.pconline.com.cn; } |
會(huì)見就會(huì)直接跳轉(zhuǎn)到j(luò)d.com。