When I access index.php, it works fine. But on localhost/pset7, it gives a 403.

Here is the permission log,

-rw-r--r--. 1 root        root          51 Jul 31 14:21 index.html
-rw-r--r--. 1 root        root          51 Jul 31 14:15 index.php
drwxrwxr-x. 5 my_user my_user 4096 Jul 31 15:13 pset7

I need to run it on the webserver so please tell me how to set correct permissions and solve this issue.

Using LEMP on CentOS.

If you need any other information/logs, just ask.

Edit1, nginx config- http://pastebin.com/K3fcWgec


  • Show your config. What do you expect to get on localhost/pset7?
    – Alexey Ten
    Commented Jul 31, 2014 at 11:05
  • Here is the nginx config, pastebin.com/K3fcWgec Inside pset7 there are three folders, public, templete and include. I expect the index.php to run from public folder.
    – user1502
    Commented Jul 31, 2014 at 11:19

2 Answers 2


The reason this is happening is that nginx doesn't allow listing directory contents by default.

So, if nginx cannot find the files specified with the index directive in a directory, it will return 403 error code.

If you want to allow directory listings, you can use the autoindex directive in the configuration block:

location /pset7 {
    autoindex on;

You should also move your root and index directives from the location / block to the server level, so that your config would look like this:

server {
    listen 80;
    server_name localhost;

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

    location /pset7 {
        autoindex on;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;

The reason you're seeing this, is that the "pset7" is not added to the Nginx configuration. All you need to do is add the following to your Nginx config

    location /pset7 {
    root   /var/www/html; # Put this somewhere else, probably in the beginning of your config instead of here, if possible.
    index  index.html index.htm index.php;
  • Still getting a 403. pset7 folder has three folders, public, template and include, do they have anything to do with the config file? Basically I want this project to run, but cant figure out whats wrong.
    – user1502
    Commented Jul 31, 2014 at 13:05
  • Not that I know of, I do not have any sub-folders written to the configuration, as the parent config takes care of that. Do you have an index.html, index.html or index.php if your folder? If not, it might give an error as it tries to seek for something that it doesn't have access to (which is to show the whole tree folder). Commented Jul 31, 2014 at 15:48
  • It is not a good idea to use root inside location directives. Commented Aug 2, 2014 at 2:35
  • @TeroKilkanen I agree, not sure why I put it there, my apologizes. Commented Aug 2, 2014 at 8:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .