Tips / Nginx

403 Forbidden error at Nginx

Many times you will face a 403 Forbidden error using Nginx webserver, and also most times, it is not related to Nginx itself. 403 Forbidden error means you don’t have permission to access that part of the web. This error can be caused by many reasons, and here we will study this reasons one by one.

Wrong directory permissions and 403 Forbidden error

One of the reasons you will see a 403 Forbidden error using Nginx is that your directory permissions are not set ok. To fix this:

  • Set 755 permissions from your FTP client to the affected directory.
  • Set 755 permissions from the shell, using chmod 755 /path/of/your/directory/ -v

Wrong file permissions and 403 Forbidden error

Same case as the previous one, try using this fix:

  • Set 644 permissions from your FTP client to the affected file.
  • Set 644 permissions from the shell, using chmod 755 /path/of/your/filename.php -v

Directory restrictions by IP and 403 Forbidden error

Check your nginx.conf file, or your sites nginx .conf file in case you have an allow/deny rule that may be blocking your network, for example:

location / {

  # block Tom's computer.

  # allow anyone else in

  # drop rest of the connections
  deny    all;


Lack of index files and 403 Forbidden error

When you don’t have any files uploaded named as ‘index’ (it could be index.php, index.html, index.shtml, etc) this is a common reason it will show a 403 Forbidden error.

Autoindex is off

If you don’t have any index file, but also have autoindex off set at Nginx config, you will have to turn it on using this method:

location /mydirectory {
        autoindex on;
        autoindex_exact_size off;
autoindex on: Turn auto indexing on
autoindex_exact_size off: Show file sizes rounded in kb/mb/gb


Additional Resources

Popular search terms:

  • 403 Forbidden nginx
  • nginx 403 forbidden
  • nginx 403
  • 403 forbidden

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking

  • Ravenman

    Autoindex off explanation saves my Nginx installation. A lot of thanks.

  • autoindex did the magic for my wordpress site 🙂 thanks mate.

  • borgulas

    For me it was the lack of index files. When I saw it it made sense. Great documentation!

  • CS

    I think it is worth noting that 403 will also be returned on fedora 20+ systems whom do not have the correct SELinux context.

    This may be solved using

    chcon -R -t httpd_sys_content_t /PATH/TO/ROOT/DIR

    • Osama bin Login

      this one did it for me. Thanks!!

    • Wow , this work !!
      Thanks. Especially for /home on DigitalOcean

  • chown -R nginx:nginx *

  • Artur Oganesyan

    In my case, i have
    Correct permissions (755 for ALL in folder)
    have no Deny block in .conf
    have index file
    have no ‘autoindex’ code
    But i still get 403, after restart nginx
    And 404 for my info.php page