Nginx 403错误:[文件夹]的目录索引被禁止 [英] Nginx 403 error: directory index of [folder] is forbidden
问题描述
我有3个域名,并且试图使用Nginx托管一个服务器(数字海洋水滴)上的所有3个网站。
mysite1.name
mysite2.name
mysite3.name
其中只有1个可用。
在我的nginx错误日志中,我看到: [error] 13108#0 :* 1目录索引/usr/share/nginx/mysite2.name/live/被禁止
。
我的网站启用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;
}
}
所有3个站点具有几乎相同的配置文件。 p>
每个站点的文件都在/usr/share/nginx/mysite1.name/someFolder等文件夹中,然后/usr/share/nginx/mysite1.name/live是一个符号链接对此。 (与mysite2和mysite3相同。)
我看过 Nginx 403禁止所有文件,但没有帮助。
有关可能出错的任何想法吗?
此配置适用于我:
server {
server_name www.mysite2.name;
return 301 $ scheme://mysite2.name$request_uri;
}
server {
#此配置基于https://github.com/daylerees/laravel-website-configs/blob/6db24701073dbe34d2d58fea3a3c6b3c0cd5685b/nginx.conf
server_name mysite2 。名称;
#我们项目的公共目录的位置。
root / usr / share / nginx / mysite2 / live / public /;
#指向Laravel前控制器的点索引。
index index.php;
location / {
#尝试的URL,包括漂亮的URL。
try_files $ uri $ uri / /index.php?$query_string;
}
#删除尾部斜杠以请路由系统。
if(!-d $ request_filename){
rewrite ^ /(。+)/ $ / $ 1 permanent;
}
#将PHP脚本传递给FastCGI服务器侦听127.0.0.1:9000
location〜\.php $ {
fastcgi_split_path_info ^(。+ \\ \\.php)(/.+)$;
##注意:你应该有cgi.fix_pathinfo = 0;在php.ini
##与php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
}
}
是一个Laravel错误:Whoops,看起来像出了错。
一个BAD IDEA可以解决这个问题将是 chmod -R 777 app / storage
(我在这里找到: http://stackoverflow.com/a/18624752/470749 )。
我认为 chmod -R 755 app / storage
更安全。
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?
I found a good example here: https://github.com/daylerees/laravel-website-configs/blob/6db24701073dbe34d2d58fea3a3c6b3c0cd5685b/nginx.conf
This config worked for me:
server {
server_name www.mysite2.name;
return 301 $scheme://mysite2.name$request_uri;
}
server {
#This config is based on https://github.com/daylerees/laravel-website-configs/blob/6db24701073dbe34d2d58fea3a3c6b3c0cd5685b/nginx.conf
server_name mysite2.name;
# The location of our project's public directory.
root /usr/share/nginx/mysite2/live/public/;
# Point index to the Laravel front controller.
index index.php;
location / {
# URLs to attempt, including pretty ones.
try_files $uri $uri/ /index.php?$query_string;
}
# Remove trailing slash to please routing system.
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Then the only output in the browser was a Laravel error: "Whoops, looks like something went wrong."
One BAD IDEA that could fix that problem would be chmod -R 777 app/storage
(which I found here: http://stackoverflow.com/a/18624752/470749). But making something world-writable is bad security.
I think chmod -R 755 app/storage
works and is more secure.
这篇关于Nginx 403错误:[文件夹]的目录索引被禁止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!