You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Nginx自定义500、502错误页面本地环境不生效排查求助

Troubleshooting Your Local Docker Nginx Custom Error Pages

Hey Nick, welcome to Stack Overflow! 😊 Great job narrowing down that your config works in development but fails locally—this usually points to environment-specific quirks rather than the Nginx config itself. Let’s walk through the most likely fixes for your local setup:

  • Verify the error.html file exists and has correct permissions
    Since your Nginx root is set to /var/www/html/public, make sure error.html is placed exactly in that directory inside the container. If you’re using a volume mount from your local machine, double-check:

    • The file is present in your local public folder (and syncing to the container)
    • The container’s www-data user has read access to it. Fix permissions by running this inside the Nginx container:
      chown www-data:www-data /var/www/html/public/error.html
      chmod 644 /var/www/html/public/error.html
      
  • Rule out VirtualBox shared folder sync issues
    Your config already has sendfile off (smart call for Vagrant/VirtualBox), but shared folders can still have sync delays or failures. Try:

    • Restarting the Nginx container to force it to pick up the file: docker restart <your-nginx-container-name>
    • Temporarily copying error.html directly into the container (bypassing the mount) to test if sync is the problem:
      docker cp ./local/public/error.html <your-nginx-container-name>:/var/www/html/public/error.html
      
  • Disable browser caching or use incognito mode
    Browsers often cache error pages, especially if you’ve tested the default 502 multiple times. Open a private/incognito window and hit your /get_error endpoint again—this ensures you’re not seeing a cached version of the default page.

  • Inspect Nginx logs for direct clues
    Check the Nginx container’s logs to see if it’s having trouble accessing error.html:

    docker logs <your-nginx-container-name> | grep error.html
    

    Look for lines like Permission denied or File not found—these will directly tell you why the custom page isn’t loading.

  • Toggle fastcgi_intercept_errors for PHP-related errors
    While your /get_error test is a pure Nginx 500, if you’re seeing the default 502 when PHP-FPM is down, try setting fastcgi_intercept_errors on in your PHP location block. Right now you have it set to off—changing this tells Nginx to intercept FastCGI errors and use your custom page instead of letting PHP-FPM send its own. Since your config works in dev, it’s possible that environment has this setting enabled implicitly.

Since your config works in development, the issue is almost certainly a local setup hiccup. Start with checking the file existence/permissions and logs—those are the most common culprits in Docker environments.

内容的提问来源于stack exchange,提问作者Nick Bardi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 06:32:39