Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I use Ubuntu Server 10.10 and have installed Nginx web server with apt-get install nginx. It creates a default web page at /var/www/nginx-default/ and that directory has the permissions drwxr-xr-x 2 root root.

When I access the default site on http://localhost/ I get this message on the page 403 Forbidden.

How should I set the file permissions on the www root so I can secure access the web pages? Or is there something else that I have to change?

share|improve this question
    
NOTE: the whole full path to your final folder must be accessible! Not even one folder in the middle. –  Lucio Nov 3 '13 at 5:53
add comment

2 Answers 2

up vote 7 down vote accepted

I usually stick to a 755 (or rwxr-xr-x) on my web root, but I do not think this is the issue you're running into since your directory is already set to that. nginx should have access to your directory. The question then becomes the permissions (or existence of) the file you're trying to access. The files within your directory will need to be readable by the user nginx is running as. I usually leave these files set to a 755 (the same as the directory). You can change the entire directory by doing sudo chmod -R 755 /var/www/nginx-default/.

If there is not an index file in the directory, however, you will still get the same error. The index file is used when you request a directory that doesn't have directory listings enabled. The most common index file is index.html. This default can be edited in your config, however, using something like:

location / {
    index index.php;
}

If you want nginx to generate a list of files in that directory for you, simply turn on directory indexing, like so:

location  /  {
  autoindex  on;
}
share|improve this answer
    
No I have an index.html in that directory. –  Jonas Oct 25 '10 at 15:33
    
What permissions does your index.html have, then? –  Jack M. Oct 25 '10 at 15:36
    
Thanks, the confiugration file actually pointed to /var/www/ and the generated index.html was placed in /var/www/nginx-default/ so I had to copy that file with cp /var/www/nginx-default/index.html /var/www/ after that I could visit the site with my web browser. –  Jonas Oct 25 '10 at 16:22
add comment

I would suggest changing the group of your webroot to www-data, the user used by nginx and also php5-fpm.

For example:

sudo chown -R my-user:www-data /webdirectory
sudo chmod -R 0755 /webdirectory

where my-user is your own account (which enables you to put the files easy in your webroot without sudo).

share|improve this answer
    
Thanks, the commands executed without any problems, but I still get 403 Forbidden when acessing it with a web browser. –  Jonas Oct 25 '10 at 15:59
    
@Jonas, I would suggest to check your nginx error log to see what the problem was. –  Peter Smit Oct 25 '10 at 16:01
    
Thanks, I found the error, it was in the error log. See my comment to Jacks answer. –  Jonas Oct 25 '10 at 16:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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