我有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禁止所有文件,但这没有帮助。

有什么问题吗?


当前回答

在我的例子中,我没有运行这个命令

sudo apt-get install php7.4-fpm

其他回答

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

您需要对静态文件目录执行权限。此外,它们需要被你的nginx用户和组咀嚼。

location ~* \.php$ {
    ...
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;    
}

改变默认的

fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

to

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

解决了我的问题。

如果你只是想列出目录内容,使用autoindex on;如:

location /somedir {
       autoindex on;
}

server {
        listen   80;
        server_name  example.com www.example.com;
        access_log  /var/...........................;
        root   /path/to/root;
        location / {
                index  index.php index.html index.htm;
        }
        location /somedir {
               autoindex on;
        }
}

看起来像是权限问题。

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

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