1

I created a websites folder into the / directory, and gave it full permission with sudo chmod -R 777 /websites/.

After that, I made a change in /etc/nginx/conf.d/default.conf to point to the websites directory:

server {
    listen       80;
    server_name  localhost;

    location / {
        root   /websites;
        index  index.html index.htm;
    }


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

}

But I am having an 403 Forbidden, when I tried to browse to public ip of the server.

Why is it happening? How can I solve it?

I have this in the nginx error.log:

2017/08/27 20:41:03 [error] 3849#3849: *37 "/websites/index.html" is
forbidden (13: Permission denied), client: **.**.130.159, server:
localhost, request: "GET / HTTP/1.1", host: "**.**.**.120"
2
  • What do you have in logs in /var/log/nginx? Do you have an index page, such as /websites/index.html? What system/distribution are you using?
    – sebasth
    Commented Aug 27, 2017 at 17:43
  • 2
    Possibly wrong permissions on the file/folder, or/and SELinux policy not permitting access. If you have SELinux enabled you should check audit logs (tools such as audit2why might be helpful).
    – sebasth
    Commented Aug 27, 2017 at 17:52

2 Answers 2

7

The error log very clearly says:

  • Your nginx would try to read /websites/index.html, but it can't
  • This is why it gives 403 error, not because of its configuration.

It is because of the 13: Permission denied. It is a system error. Thus, your nginx is configured well, it tries to read that file, but it can't.

The next question is, why it can't. First, you should check, what it does. Sudo to the user, on which nginx is running (it is probably www-data, so the command is: sudo -u www-data /bin/bash), and try to read that file for yourself (cat /websites/index.html).

The next step depends on, what is the result.

@sebasth has right in his comment:

Possibly wrong permissions on the file/folder, or/and SELinux policy not permitting access. If you have SELinux enabled you should check audit logs (tools such as audit2why might be helpful).

I think the two most probable outcomes:

  1. Something wasn't set up correctly with the permissions, despite that your chmod command looks okay
  2. There is some SELinux thingy making your life nicer.
1
  • 1
    WOW Thank you very much man!! I just test it if it will work, and i run setenforce permissive - and it works!! Tanks again! i take the information from here: digitalocean.com/community/tutorials/…
    – Shilo
    Commented Aug 27, 2017 at 21:57
-3
chmod 777 /var/www/your_site 

solved the issue

1
  • 2
    besides the typo, this is generally not good advice (see the accepted answer)
    – Jeff Schaller
    Commented Mar 23, 2019 at 15:21

You must log in to answer this question.

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