Nginx - Error 403 when accessing /


I am working using the Nginx web server, but it is throwing a 403 error when accessing /, except when accessing /index.php directly or another existing file. Files and non-existent directories throw a 403 error as well.

Error 403 = Prohibited / Forbidden

This is my configuration file:

# Configuration file for
server {
 # Listen on port 80
 listen 80;
 # This configuration file is only valid if the IP/hostname used is

 # Root directory
 root /home/web/;
 # Index file
 index index.php;

 # Enables PageSpeed
 pagespeed on;
 # Images
 pagespeed DisableFilters lazyload_images;
 # Combine JavaScript/CSS
 pagespeed EnableFilters combine_javascript;
 pagespeed EnableFilters combine_css;
 # Caching
 #pagespeed ForceCaching on;
 pagespeed EnableFilters extend_cache;

  # Enables PHP
 location ~ \.php$ {
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  fastcgi_index index.php;
  include fastcgi_params;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

 # Handle errors & front controller
 location / {
  # Errors
  #error_page 400 /error/400;
  #error_page 401 /error/401;
  #error_page 403 /error/403;
  #error_page 404 /error/404;
  #error_page 500 /error/500;
  # Front controller
  try_files $uri $uri/ @missing;
  # Maintenance mode (comment to disable)
  deny all;

 # Front controller
 location @missing {
  rewrite ^ /index.php last;

 # Protects the app directory
 location /app {
  # Deny all requests to /app
  deny all;
  # Return a 403 forbidden error
  return 403;


At the same time, I would appreciate checking if the front controller is OK, because it does not look like it. I want all requests for URI / whatever / etc to be sent to index.php. With PHP, I use delimiters to separate each string URI by / .

Thanks for your answers.

PS: I commented on the error pages thinking that I was going to solve the problem, but it really did not work. I tried deleting several rules too, plus, the rule of deny all is because the site is in maintenance, but I see that my IP has changed because it is dynamic and I could still access /index.php.

asked by Derek Nichols 07.08.2017 в 22:54

1 answer


In Nginx the rewrite rules for something so "simple" I would use

location / {
try_files $uri $uri/ /index.php?$args;

This forwards everything to the index.php file, attaching the other parameters below.

You have all the detailed information in link

answered by 16.09.2017 в 21:31