title: Nginx, PHP + FPM Custom Error Pages
body: <p>I am trying to create some custom error pages but can't seem to get the 500 one working.</p>
  
  <p>I have the following config:</p>
  
  <pre><code>server {
      listen 80;
  
      root /var/www/devsite;
      index index.php;
      server_name devsite;
  
      error_page 403 = /error.php?code=403;   
      error_page 404 = /error.php?code=404;
      error_page 500 = /error.php?code=500;
  
      location / {
          try_files $uri =404;
      }
  
      location ~ \.php$ {
          try_files $uri =404;
          fastcgi_pass unix:/var/run/php5-fpm.sock;
          fastcgi_index index.php;
          include fastcgi_params;
      }
  
  }
  </code></pre>
  
  <p>At first, I thought it might be because it's a PHP file so I changed:</p>
  
  <pre><code>error_page 500 = /error.php?code=500;
  </code></pre>
  
  <p>To a static page:</p>
  
  <pre><code>error_page 500 /500.html
  </code></pre>
  
  <p>But it still just shows a blank page with a 500 response code when I break some PHP code to trigger it.</p>
  
  <p>I then tried to make it the last rule inside <code>location ~ \.php$</code> but the same happens. Any ideas why the custom 500 page won't work?</p>
  
  <p>I also notice that if you try to access an "access denied" file that has the .php extension, it will not show the custom 403 page and show the built-in page instead. Is there a way to make the rule cover .php files too?</p>