0

I use the nginx config file from https://www.nginx.com/resources/wiki/start/topics/recipes/drupal/

It has return 403 and deny all on some file.
Ex. When I visit /core/CHANGELOG.txt, nginx returns default 403 Forbidden page.
I want it to display drupal 403 error page not nginx white default 403 page.

I have tried adding error_page 403 /403 but it returns

Not Found

The requested URL "http://mysite/core/CHANGELOG.txt" was not found on this server.

5
  • location ~ ^/core/.*\.txt$ { return 403; } Add this in your conf file. I hope this should work. – sarathkm Nov 7 '16 at 12:43
  • @sarathkm From my config file, I already have deny all on all .txt file so it return nginx default 403 page but what I want is to return Drupal 403 page that I set in /admin/config/system/site-information. – Thew Nov 7 '16 at 13:08
  • Then you need to let Drupal handle the errors instead of nginx as you have configured nginx to do so. – mradcliffe Nov 7 '16 at 13:26
  • @mradcliffe Is there any module to use or I have to write it. – Thew Nov 7 '16 at 13:53
  • Quoting yourself "I already have deny all on all .txt file so it return nginx default 403 page". So undo that? – mradcliffe Nov 7 '16 at 15:24
0

What you need to do is to configure nginx to serve a drupal page that generates a 403 page. There are severals ways to do this.

The easy solution is to route the traffic to Drupal (the index.php file), which would generate a 404 since the page doesn't exist in Drupal.

I think doing

location ~* \.(txt|log)$ {
  try_files @rewrite
}

should accomplish this for .txt and .log files. It should try to serve the file from Drupal. By default this will be a 404, but you can add the a route for specific files and return 403 instead.

0

From @googletorp and my google I found this solution

I added error_page 418 = @blablabla; return 418;.

location ~* \.(txt|log)$ {
    allow 192.168.0.0/16;
    deny all;
    error_page 418 = @blablabla; return 418;
}

location @blablabla {
    rewrite ^ /blablabla break;

    proxy_pass       http://localhost;
    proxy_set_header Host      $host;
    proxy_set_header X-Real-IP $remote_addr;
}

This will return to 404 page as /blablabla is not found.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.