我有3个域名,并试图使用Nginx在一台服务器上托管所有3个网站(一个数字海洋液滴)。

mysite1.name mysite2.name mysite3.name

只有1个有效。另外两个结果是403个错误(以同样的方式)。

在我的nginx错误日志中,我看到:[error] 13108#0: *1目录索引“/usr/share/nginx/mysite2.name/live/”被禁止。

我的站点启用配置是:

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

这三个站点都有几乎相同的配置文件。

每个站点的文件都在/usr/share/nginx/mysite1.name/someFolder这样的文件夹中,然后/usr/share/nginx/mysite1.name/live是指向该文件夹的符号链接。(mysite2和mysite3也是如此。)

我已经查看了Nginx 403禁止所有文件,但这没有帮助。

有什么问题吗?


当前回答

我也遇到过类似的错误 ——网页中的“403禁止” ——错误日志/var/log/nginx/error.log中的"13:Permission denied

以下3个步骤对我很有效:

1:开放式终端,看到如下内容

user1@comp1:/home/www/

因此,我的用户名是“user1”(从上面)

2:修改/etc/nginx/nginx.conf中的user

# user www-data;
user user1;

3:重新加载nginx

sudo nginx -s reload  

此外,我已经应用了文件/文件夹权限(在我做以上3步之前) (755到我的目录,说/dir1/) &(644下的文件目录): (我不确定,如果真的需要这个额外的步骤,3步以上可能就足够了):

chmod 755 ./dir1/
chmod 644 ./dir1/*.*

希望这能帮助到一些人。祝你好运。

其他回答

看起来像是权限问题。

尝试像在mysite1中那样设置其他站点的所有权限。

默认情况下,文件权限应该是644和dirs 755。 还要检查运行nginx的用户是否有权限读取这些文件和dirs。

因为你正在使用php-fpm,你应该确保php-fpm用户与nginx用户相同。

检查/etc/php-fpm.d/www.conf,如果不是,将php用户和组设置为nginx。

说明php-fpm用户需要有写权限。

以下是我如何在我的Kali机器上修复它:

定位到目录: cd /etc/nginx/sites-enabled / 编辑'default'配置文件: Sudo nano默认 在location块中添加以下行: 位置/你的目录{ 自动变址; autoindex_exact_size; } 注意,我在一个特定的目录中激活了自动索引 / yourdirectory只。否则,你电脑上的所有文件夹都将启用它,而你不想要它。 现在重新启动你的服务器,它现在应该工作了: Sudo服务nginx重启

更改try_files以指向index.php路径,在你提到的“Laravel”中,它应该是这样的

location / {
    try_files $uri $uri/ /public/index.php$request_uri;
}

在“codeigniter”项目中试试这样做

location / {
    try_files $uri $uri/ /public_web/index.php$request_uri;
}

下面是工作的配置:

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错误:“哎呀,看起来好像出了什么问题。”

不要执行chmod -R 777 app/storage(注)。让某些东西在全世界都可写是很糟糕的安全性。

chmod -R 755 app/storage工作,更安全。