nginx指定404エラーページジャンプ
必要:
設定ファイルを変更してジャンプします.
本文は「精忠報国」のブログから来ました.転載はお断りします.
設定ファイルを変更してジャンプします.
server {
listen 80;
server_name shadouyou.com www.shadouyou.com;
if ($host = 'shadouyou.com' ) {
rewrite ^/(.*)$ http://www.shadouyou.com/$1 permanent;
}
root /Disk/var/www/index;
include /etc/nginx/conf.d/shadouyou-SEO;
location / {
index index.html index.htm;
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-FOR $proxy_add_x_forwarded_for;
if ( !-e $request_filename ) {
proxy_pass http://index;
}
if ($request_uri ~* newsinfor.*) {
rewrite ^(.*)$ /404.html last ;
}
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
クライアントがwww.shardouyou.com/news infor_にアクセスする時XXXX.htmlの時に最後のifブロックで下の404.htmlのlocationに書き換えられます. rootディレクトリの下に自分で書いた404のhtmlファイルをアップロードすればいいです.本文は「精忠報国」のブログから来ました.転載はお断りします.