php 403 Forbidden on nginx/1.4.6 (Ubuntu) - Laravel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33443918/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:29:27  来源:igfitidea点击:

403 Forbidden on nginx/1.4.6 (Ubuntu) - Laravel

phplaravelnginxubuntu-12.04laravel-5.1

提问by cyber8200

I keep getting 403 Forbidden

我不断得到 403 Forbidden

enter image description here

在此处输入图片说明



My settings:

我的设置:

/etc/nginx/sites-available/default

/etc/nginx/sites-available/default

default

默认

server {
        listen   80;


        root home/laravel-app/;

        index index.php index.html index.htm;

        server_name example.com;

        location / {
                try_files $uri $uri/ /index.html;
        }

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
              root /usr/share/nginx/www;
        }

        # pass the PHP scripts to FastCGI server listening on the php-fpm socket
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;

        }

}


Update

更新

I followed this instruction : here

我遵循了这条指令:here



Any hints/suggestions on this will be a huge help !

对此的任何提示/建议都将是一个巨大的帮助!

采纳答案by Ben Swinburne

You need to specify an absolute path for your rootdirective. Nginx uses the directory set at compile time using the --prefix switch. By default this is /usr/local/nginx.

您需要为root指令指定绝对路径。Nginx 使用编译时使用 --prefix 开关设置的目录。默认情况下,这是/usr/local/nginx.

What this means is that your root, which is currently set to root home/laravel-app/causes nginx to look for files at /usr/local/nginx/home/laravel-app/which presumably isn't where your files are.

这意味着您的 root(当前设置为 root)home/laravel-app/会导致 nginx 查找/usr/local/nginx/home/laravel-app/可能不是您的文件所在的文件。

If you set your rootdirective to an absolute path such as /var/www/laravel-app/public/nginx will find the files.

如果您将root指令设置为绝对路径,例如/var/www/laravel-app/public/nginx 将找到这些文件。

Similarly you'll note that I added /public/to the path above. This is because Laravel stores it's index.phpfile there. If you were to just point at /laravel-app/there's no index file and it'd give you a 403.

同样,您会注意到我添加/public/到上面的路径中。这是因为 Laravel 将它的index.php文件存储在那里。如果你只是指向/laravel-app/没有索引文件,它会给你一个 403。

回答by ali haider

you need to have a rule for php files (in the default file)

您需要为 php 文件制定规则(在默认文件中)

# pass the PHP scripts to FastCGI server listening on (...)
#
location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        # With php5-cgi alone:
        #fastcgi_pass 127.0.0.1:9000;
        # With php5-fpm:
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
}

回答by Trip

The error you added in your update indicates that nginx is attempting a directory index from your ssc-portal folder. Since you appear to be using a basic nginx installation, the only reason a directory index should fail here is if nginx is unable to find the listed index options.

您在更新中添加的错误表明 nginx 正在尝试从您的 ssc-portal 文件夹中创建目录索引。由于您似乎使用的是基本的 nginx 安装,因此目录索引失败的唯一原因是 nginx 无法找到列出的索引选项。

In your server block, you are telling nginx to try the following locations in order when a directory listing is requested (a URI that ends with a trailing slash): index.php, index.html, then index.htm.

在您的服务器块中,您告诉 nginx 在请求目录列表时按顺序尝试以下位置(以斜杠结尾的 URI):index.php、index.html,然后是 index.htm。

If none of those files is found, the directory index request fails.

如果没有找到这些文件,则目录索引请求失败。

My best guess is you have your index.php file in the wrong place. Did you move it up from the ssc-portal folder?

我最好的猜测是你的 index.php 文件放错了地方。你是从 ssc-portal 文件夹上移的吗?