Drupal configured to handle 404/403, NGINX still displays them

March 26, 2015 2.4k views
Drupal

In our /admin/config/system/site-information we have it set to allow Drupal to display a designed/themed 403/404 page:

Default 403 (access denied) page /customerror/403
This page is displayed when the requested document is denied to the current user. Leave blank to display a generic "access denied" page.

Default 404 (not found) page customerror/403

However, the Nginx default is still displaying:
404 Not Found
nginx/1.4.6 (Ubuntu)

Our custom Nginx config file has this:

error_page 403 /customerror/403;

error_page 404 /404.html;

Should the latter also be commented out?

1 comment
  • Can you share your full nginx conf for this site? It sounds like you may either need to pass the request directly to the script with parameters rather than using the rewritten url for your error page or your nginx configuration requires some other changes.

2 Answers

How do I "pass the request directly to the script with parameters "?

server {
listen 80 defaultserver;
listen [::]:80 default
server ipv6only=on;

root /var/www/example/html;
index index.php index.html index.htm;

error_page 403 /customerror/403;

errorpage 404 /404.html;
error
page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

location = /favicon.ico {
lognotfound off;
access_log off;
}

location = /robots.txt {
allow all;
lognotfound off;
access_log off;
}

location ~ ../..php$ {
return 403;
}

location ~ ^/sites/.*/private/ {
return 403;
}

location /wordpress {
return 403;
}

location /getmoreinfo {
return 403;
}

location /fckeditor {
return 403;
}

location /teaching-artist {
rewrite /teaching-artist/(.)$ http://example/teaching-artist/$1;
}
location /print/content {
rewrite /print/content/(.
)$ http://example/print/content/$1;
}

location /content {
rewrite ^/content/([^]*)([^]*)([^]*)([^]*)([^]*)([^]*)([^]*)([^]*)(.)$ http://centerforartsed.org/mediaclips/$1-$2-$3-$4-$5-$6-$7-$8-$9;
rewrite ^/content/([^_]
)([^])([^])([^])_(.)$ http://example.org/mediaclips/$1-$2-$3-$4-$5;
rewrite ^/content/([^]*)([^]*)(.)$ http://example.org/mediaclips/$1-$2-$3;
rewrite ^/content/([^_]
)_(.*)$ http://example.org/mediaclips/$1-$2;
}

location /wpadmin {
return 403;
}

location ~ (^|/). {
return 403;
}

location / {
try_files $uri @rewrite;
}

location @rewrite {
rewrite ^ /index.php;
}

location ~ .php$ {
fastcgisplitpathinfo ^(.+.php)(/.+)$;
include fastcgi
params;
fastcgiparam SCRIPTFILENAME $requestfilename;
fastcgi
intercepterrors on;
fastcgi
pass unix:/var/run/php5-fpm.sock;
}

location ~ ^/sites/.*/files/styles/ {
try_files $uri @rewrite;
}

location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
lognotfound off;
}
}

If it helps any Googlers, I just set the 404 in Drupal UI and then commented out the line

error_page 404 /404.html;

which I found in /etc/nginx/sites-available/ in a file called drupal

I then did 'service nginx restart' and it worked.

Have another answer? Share your knowledge.