注意:只通过 Nginx 返回错误页面
1. 在nginx默认获取页面的目录,存放好对应的 html、css、images等文件。如下:
root@dev:~$ ll /usr/share/nginx/html total 64 drwxr-xr-x 5 root root 4096 11月 9 15:15 ./ drwxr-xr-x 3 root root 4096 5月 9 2018 ../ -rw-r--r-- 1 root root 8453 11月 9 15:02 404.html drwxr-xr-x 2 root root 4096 11月 9 15:10 css/ -rw-r--r-- 1 root root 8231 11月 9 15:10 error_cn.html -rw-r--r-- 1 root root 8458 11月 9 15:10 error_en.html drwxr-xr-x 2 root root 4096 11月 9 15:10 images/ -rw-r--r-- 1 root root 2347 11月 9 15:10 muse_manifest.xml drwxr-xr-x 2 root root 4096 11月 9 15:10 scripts/ -rw-r--r-- 1 root root 1048 11月 9 15:10 sitemap.xml
2. 在 Nginx 里面配置重定向 (按照浏览器的语言分别给出不同的页面)
map $http_accept_language $lang { default en; ~zh-TW cn; ~zh-HK cn; ~zh-CN cn; } server { listen 80; server_name 127.0.0.1; error_page 404 /error_$lang.html;
# 因为不同的版本可能默认目录不一样,所以在 location 里面指定错误页面的目录比较好。
location /error_$lang.html {
root /usr/share/nginx/html;
}
location / { # try_files $uri.$lang.html $uri =404;
return 404; } }
浙公网安备 33010602011771号