本文介绍了Nginx 403 错误:[文件夹] 的目录索引被禁止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 3 个域名,我正在尝试使用 Nginx 在一台服务器(Digital Ocean Droplet)上托管所有 3 个站点.

I have 3 domain names and am trying to host all 3 sites on one server (a Digital Ocean droplet) using Nginx.

mysite1.namemysite2.namemysite3.name

mysite1.namemysite2.namemysite3.name

其中只有 1 个有效.另外两个导致 403 错误(以同样的方式).

Only 1 of them works. The other two result in 403 errors (in the same way).

在我的 nginx 错误日志中,我看到:[error] 13108#0: *1 directory index of "/usr/share/nginx/mysite2.name/live/" is forbidden.

In my nginx error log, I see: [error] 13108#0: *1 directory index of "/usr/share/nginx/mysite2.name/live/" is forbidden.

我启用站点的配置是:

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 个站点都有几乎相同的配置文件.

All 3 sites have nearly identical config files.

每个站点的文件都位于/usr/share/nginx/mysite1.name/someFolder 等文件夹中,然后/usr/share/nginx/mysite1.name/live 是指向该文件夹的符号链接.(同样适用于 mysite2 和 mysite3.)

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.)

我查看了 Nginx 403 禁止所有文件 但这没有帮助.

I've looked at Nginx 403 forbidden for all files but that didn't help.

对可能出现的问题有什么想法吗?

Any ideas on what might be wrong?

推荐答案

这是有效的配置:

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;
    }

}

然后浏览器中唯一的输出是 Laravel 错误:哎呀,好像出了点问题."

Then the only output in the browser was a Laravel error: "Whoops, looks like something went wrong."

请勿运行 chmod -R 777 app/storage(注意).使某些东西成为世界可写的东西是很糟糕的安全性.

Do NOT run chmod -R 777 app/storage (note). Making something world-writable is bad security.

chmod -R 755 app/storage 有效且更安全.

这篇关于Nginx 403 错误:[文件夹] 的目录索引被禁止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-19 02:10