2013-10-10 01:00:28 8 Comments
I have 3 domain names and am trying to host all 3 sites on one server (a Digital Ocean droplet) using Nginx.
mysite1.name mysite2.name mysite3.name
Only 1 of them works. The other two result in 403 errors (in the same way).
In my nginx error log, I see: [error] 13108#0: *1 directory index of "/usr/share/nginx/mysite2.name/live/" is forbidden
.
My sites-enabled config is:
server {
server_name www.mysite2.name;
return 301 $scheme://mysite2.name$request_uri;
}
server {
server_name mysite2.name;
root /usr/share/nginx/mysite2.name/live/;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.html index.php;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
All 3 sites have nearly identical config files.
Each site's files are in folders like /usr/share/nginx/mysite1.name/someFolder, and then /usr/share/nginx/mysite1.name/live is a symlink to that. (Same for mysite2 and mysite3.)
I've looked at Nginx 403 forbidden for all files but that didn't help.
Any ideas on what might be wrong?
Related Questions
Sponsored Content
14 Answered Questions
[SOLVED] 403 Forbidden vs 401 Unauthorized HTTP responses
- 2010-07-21 07:21:58
- VirtuosiMedia
- 803103 View
- 2141 Score
- 14 Answer
- Tags: http-headers http-status-code-403 http-status-codes http-status-code-401 http-response-codes
3 Answered Questions
2 Answered Questions
34 Answered Questions
[SOLVED] Error message "Forbidden You don't have permission to access / on this server"
- 2012-06-03 19:30:34
- Dmytro Zarezenko
- 1977695 View
- 488 Score
- 34 Answer
- Tags: apache configuration httpd.conf http-status-code-403
9 Answered Questions
[SOLVED] Nginx 403 forbidden for all files
- 2011-07-22 19:53:51
- Angus Ireland
- 197481 View
- 167 Score
- 9 Answer
- Tags: nginx centos http-status-code-403 php
1 Answered Questions
12 Answered Questions
[SOLVED] Why does Nginx return a 403 even though all permissions are set properly?
- 2014-03-23 02:01:55
- Adam Pearlman
- 43743 View
- 39 Score
- 12 Answer
- Tags: nginx installation http-status-code-403
1 Answered Questions
2 Answered Questions
3 Answered Questions
[SOLVED] 403 forbidden on wordpress index with nginx, the rest of the pages work fine
- 2013-08-07 18:58:21
- Alban Dumouilla
- 15741 View
- 7 Score
- 3 Answer
- Tags: wordpress nginx http-status-code-403
15 comments
@Ryan 2013-10-10 17:46:28
Here is the config that works:
Then the only output in the browser was a Laravel error: “Whoops, looks like something went wrong.”
Do NOT run
chmod -R 777 app/storage
(note). Making something world-writable is bad security.chmod -R 755 app/storage
works and is more secure.@OrangeTux 2014-03-15 11:03:52
NEVER run
chmod -R 777
to get things working!@Ryan 2014-05-14 14:32:45
Yeah, you guys are right; that's a bad idea. I'll update my answer. People also might benefit from stackoverflow.com/a/11996645/470749
@complistic 2014-05-16 02:17:37
You may also have the option of changing the folders group to the nginx group ie
www-data
on debian. Then setting even stricter permissions on the folder like:chmod -R 640 app/storage
thenchown -R :www-data app/storage
. This way the files are only visible to the app owner and the web server. And no-one at all can execute any of the stored (possibly uploaded) files directly. Nginx should only need read permission to access the files.@Ryan 2014-06-02 00:29:42
Note to self: I just got this Nginx 403 again and again the problem was that I had accidentally left off
public/
onroot /usr/share/nginx/mysitename/public/;
. After addingpublic/
and runningservice nginx restart
, it worked.@zeros-and-ones 2018-02-12 05:50:59
For me the problem was that any routes other than the base route were working, adding this line fixed my problem:
Full thing:
@JCM 2016-06-27 04:49:26
If you have directory indexing off, and is having this problem, it's probably because the try_files you are using has a directory option:
Remove it and it should work:
From what I can see, this is caused because nginx will try to index the directory, and be blocked by itself. Throwing the error mentioned by OP.
@Travis D 2016-10-06 00:15:54
This is exactly the problem I was having. I could not understand why
try_files
was not tryingindex.php
, I just kept getting 403 with "directory index of ... is forbidden"@joseluisq 2016-11-09 17:52:05
I removed
$uri/
and it works@pixeline 2016-11-26 23:44:27
same here: this is my accepted answer :)
@Ian Dunn 2017-04-13 20:49:56
@JCM, would you mind adding an explanation of why having
$uri/
creates a problem?@alariva 2017-06-06 19:22:52
Solved mine as well
@JCM 2017-06-09 21:46:41
@IanDunn because nginx will try to index the directory, and be blocked by itself. Throwing the error mentioned by OP.
@Ours 2017-10-04 11:27:15
Been looking for that all morning, couldn't figure it out. Thanks a lot!
@Ali Hashemi 2017-04-08 19:58:32
Because you're using
php-fpm
, you should make sure thatphp-fpm
user is the same asnginx
user.Check
/etc/php-fpm.d/www.conf
and set php user and group tonginx
if it's not.The
php-fpm
user needs write permission.@theDrifter 2016-03-30 13:21:53
I had the same problem, the logfile showed me this error:
I am hosting a PHP app with codeignitor framework. When i wanted to view uploaded files i received a
403 Error
.The problem was, that the
nginx.conf
was not properly defined. Instead ofi only included
I have an index.php in my root and i thought that was enough, i was wrong ;) The hint gave me NginxLibrary
@mboy 2016-07-04 17:46:14
Thank man.. I was with the same boat.. I spent hours figuring out why my wordpress do't work at all! index directive is needed in the nginx main config for my wordpress installation to work
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
index index.html index.htm index.php;
@GeekHades 2018-02-28 07:04:37
It works for me!
@wave_1102 2015-03-12 12:49:21
Change default
to
solved my problem.
@Raunaq Kochar 2016-02-17 12:45:51
I was running Ubuntu 15.10 and encountered the 403 Forbidden error due to a simple reason. In the nginx.conf(configuration file for nginx), the user was 'www-data'. Once I changed the username to [my username], it worked fine assuming the necessary permissions were given to my username. Steps followed by me:
My configuration file looks like this:
@Manohar Reddy Poreddy 2015-08-19 07:22:16
I encountered similar error
--- "403 Forbidden" in the webpage
--- "13: Permission denied" in the error log at /var/log/nginx/error.log
Below 3 Steps worked for me:
1: Open Terminal, saw something like below
So, my user name is "user1" (from above)
2: Changed user in /etc/nginx/nginx.conf
3: Reloaded the nginx
Additionally, I have applied file/folder permissions (before I did above 3 steps)
(755 to my directory, say /dir1/) & (644 for files under that directory):
(I am not sure, if this additional step is really required, just above 3 steps might be enough):
Hope this helps quick someone. Best of luck.
@Altaf Hussain 2015-09-15 07:10:51
Thanks bro, i had the same issue, and it was because of permissions. I set folder and file permissions, and now it is working fine.
@Manohar Reddy Poreddy 2015-09-15 07:39:08
Glad to hear I am helpful. (Help others, in your known domain, in your free time, if possible, without expecting anything back)
@Sandeep C 2018-05-22 11:15:45
This worked! Thanks!
@Manohar Reddy Poreddy 2018-05-23 12:26:34
Glad to hear it helped.
@Cameron Kerr 2015-09-26 19:06:18
You might get this because of Nginx policy (eg. "deny"), or you might get this because of Nginx misconfiguration, or you might get this because of filesystem restrictions.
You can determine if its the later (and possibly see evidence of a misconfiguration by using strace (except, the OP won't have access to that):
Here I'm inspecting the filesystem activity done by nginx while a ran a test (I had the same error as you).
Here's a selected part of my config at the time
In my case, as strace quite clearly shows, the joining of in the "alias" to the "index" was not what I had expected, and it seems I need to get into the habit of always appending directory names with a /, so in my case, the following worked:
@kzahel 2016-03-03 19:41:34
Thanks for this. I knew I did not have a permissions problem and your comment helped me find the solution. I added a "/" to the end of my alias and it works fine.
@Agung Prasetyo 2016-11-11 17:08:09
you are my hero @Cameron Kerr, based on my experience the problem is nginx raise 403 for not found files on alias directory e.g
/home/web/public
. Why nginx try to access these not found files is because i forgot to remove this lineindex index.html index.htm index.nginx-debian.html;
since thats files is not inside my public dir.@Haimei 2015-02-24 04:23:07
In fact there are several things you need to check. 1. check your nginx's running status
Here we need to check who is running nginx. please remember the user and group
check folder's access status
ls -alt
compare with the folder's status with nginx's
(1) if folder's access status is not right
(2) if folder's user and group are not the same with nginx's running's
and change nginx's running username and group
to find where is nginx configuration file
Because nginx default running's user is nobody and group is nobody. if we haven't notice this user and group, 403 will be introduced.
@maz 2013-11-15 18:11:22
If you're simply trying to list directory contents use
autoindex on;
like:@Ryan 2014-05-14 14:37:30
I definitely don't want
autoindex on
; it would be a bad idea to expose my directory contents to the public.@Bhargav Nanekalva 2014-12-17 06:38:59
@Ryan It always comes down to "What do you want to do?"
@Joe 2015-02-19 04:25:30
It's pretty clear he wants to remove 403 errors and get webpages to show not display the entire directory contents (esp given the discussion above)
@maz 2013-11-15 18:08:27
If you're simply trying to list directory contents use
autoindex on;
like:@Ryan 2014-05-14 14:38:22
I definitely don't want
autoindex on
; it would be a bad idea to expose my directory contents to the public.@maz 2014-05-14 20:02:20
That's why I wrote
if
@Rhys 2013-10-11 07:44:02
You need execute permission on your static files directory. Also they need to be chown'ed by your nginx user and group.
@complistic 2014-05-16 02:13:27
I think he only need needs read permission to the nginx process?
@Mohammad AbuShady 2013-10-10 08:13:34
change the
try_files
to point to theindex.php
path, in the "Laravel" that you mentioned it should be something like thisAnd in the "codeigniter" project try it like this
@Tomahock 2013-10-10 01:21:29
It look's like some permissions problem.
Try to set all permisions like you did in mysite1 to the others site.
By default file permissions should be 644 and dirs 755. Also check if the user that runs nginx have permission to read that files and dirs.