tomcat和nginx自定义404错误页面
    		       		warning:
    		            这篇文章距离上次修改已过426天,其中的内容可能已经有所变动。
    		        
        		                
                在Tomcat中自定义404错误页面,你需要做的是在$CATALINA_HOME/conf/web.xml文件中添加或修改<error-page>元素。
例如:
<error-page>
    <error-code>404</error-code>
    <location>/custom_404.jsp</location>
</error-page>在你的Web应用的/WEB-INF/目录下创建一个custom_404.jsp文件,然后在这个文件中编写你想展示的404错误信息。
对于Nginx,你需要在Nginx配置文件中为特定的server块添加一个error_page指令。
例如:
server {
    listen       80;
    server_name  localhost;
 
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
 
    error_page  404              /custom_404.html;
    location = /custom_404.html {
        root   /usr/share/nginx/html;
        internal;
    }
 
    # 其他配置...
}在Nginx的服务器根目录(这里是/usr/share/nginx/html)下创建一个custom_404.html文件,然后编写你想展示的404错误信息。
确保重启Tomcat和Nginx以应用更改。
评论已关闭