Php 为nginx安装laravel(权限被拒绝的错误)

Php 为nginx安装laravel(权限被拒绝的错误),php,laravel,nginx,Php,Laravel,Nginx,我正在尝试为nginx设置我的laravel。我的配置: server { listen 80; server_name decoder.lan; root /var/www/decoder-now/public; index index.php; try_files $uri $uri/ @rewrite; location @rewrite { rewrite ^/(.*)$ /index.php?_url=/$1;

我正在尝试为nginx设置我的laravel。我的配置:

server {
    listen 80;
    server_name decoder.lan;
    root /var/www/decoder-now/public;

    index index.php;

    try_files $uri $uri/ @rewrite;

    location @rewrite {
        rewrite ^/(.*)$ /index.php?_url=/$1;
    }

    location @php { ## Depending on your Nginx version, you might need to change this to location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location @handler {
      rewrite / /index.php;
    }

}
我在error.log中得到错误:

  2014/11/24 15:13:43 [crit] 14063#0: *10 stat() "/var/www/decoder-now/public/index.php" failed (13: Permission denied), client: 127.0.0.1, server: decoder.lan, request: "GET /address/ HTTP/1.1", host: "decoder.lan"
    2014/11/24 15:13:43 [crit] 14063#0: *10 stat() "/var/www/decoder-now/public/index.php" failed (13: Permission denied), client: 127.0.0.1, server: decoder.lan, request: "GET /address/ HTTP/1.1", host: "decoder.lan"
    2014/11/24 15:13:43 [crit] 14063#0: *10 stat() "/var/www/decoder-now/public/index.php" failed (13: Permission denied), client: 127.0.0.1, server: decoder.lan, request: "GET /address/ HTTP/1.1", host: "decoder.lan"
    2014/11/24 15:13:43 [crit] 14063#0: *10 stat() "/var/www/decoder-now/public/index.php" failed (13: Permission denied), client: 127.0.0.1, server: decoder.lan, request: "GET /address/ HTTP/1.1", host: "decoder.lan"
    2014/11/24 15:13:43 [crit] 14063#0: *10 stat() "/var/www/decoder-now/public/index.php" failed (13: Permission denied), client: 127.0.0.1, server: decoder.lan, request: "GET /address/ HTTP/1.1", host: "decoder.lan"
    2014/11/24 15:13:43 [crit] 14063#0: *10 stat() "/var/www/decoder-now/public/index.php" failed (13: Permission denied), client: 127.0.0.1, server: decoder.lan, request: "GET /address/ HTTP/1.1", host: "decoder.lan"
    2014/11/24 15:13:43 [crit] 14063#0: *10 stat() "/var/www/decoder-now/public/index.php" failed (13: Permission denied), client: 127.0.0.1, server: decoder.lan, request: "GET /address/ HTTP/1.1", host: "decoder.lan"
    2014/11/24 15:13:43 [crit] 14063#0: *10 stat() "/var/www/decoder-now/public/index.php" failed (13: Permission denied), client: 127.0.0.1, server: decoder.lan, request: "GET /address/ HTTP/1.1", host: "decoder.lan"
    2014/11/24 15:13:43 [crit] 14063#0: *10 stat() "/var/www/decoder-now/public/index.php" failed (13: Permission denied), client: 127.0.0.1, server: decoder.lan, request: "GET /address/ HTTP/1.1", host: "decoder.lan"
    2014/11/24 15:13:43 [crit] 14063#0: *10 stat() "/var/www/decoder-now/public/index.php" failed (13: Permission denied), client: 127.0.0.1, server: decoder.lan, request: "GET /address/ HTTP/1.1", host: "decoder.lan"
    2014/11/24 15:13:43 [error] 14063#0: *10 rewrite or internal redirection cycle while redirect to named location "@rewrite", client: 127.0.0.1, server: decoder.lan, request: "GET /address/ HTTP/1.1", host: "decoder.lan"
本例使用url:decoder.lan/address,但decoder.lan/不起作用

access.log文件:

127.0.0.1 - - [24/Nov/2014:15:13:43 +0300] "GET /address/ HTTP/1.1" 500 603 "-" "Mozilla/5.0 (X11; Linux i686 (x86_64)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36"
我试着检查工作,听不听这个文件。我通过控制台中的命令进行检查:

sudo -u www-data cat index.php
从控制台打开了一个文件

我使用www-data-user,因为在/ect/php5/fpm/pool.d/www.conf中我有:

listen.owner = www-data
listen.group = www-data
listen.mode = 0660
在…/decoder now/public/文件夹中的文件列表:

-rwxr-xr-x 1 www-data  www-data 2238 нояб. 17 19:01 favicon.ico
-rwxrwxrwx 1 www-data  www-data 1586 нояб. 17 19:01 index.php
drwxr-xr-x 2 www-data  www-data 4096 нояб. 17 19:01 packages
-rwxr-xr-x 1 www-data  www-data   24 нояб. 17 19:01 robots.txt
在这个例子中,我使用了apache服务器,但他现在已经关机了。所有请求都在nginx服务器上进行


请帮助我,抱歉我的英语不好:)

首先,您似乎有权限问题,请检查用户nginx工作进程运行的是什么(用户指令)

其次,您的
@php
@handler
位置永远不会到达

第三,您的
try\u files
指令负责生成内部重定向循环。只需举一个URL示例,花点时间思考nginx将做什么:

  • 你点击了
    http://decoder.lan/address/
  • try files指令在运行时相当于
    try\u files/address//address/@rewrite
  • @rewrite
    命名位置将导致重写的URI:
    /index.php?\u url=/address/
  • 未为重写指令指定标志时,默认行为是使用
    last
    标志,这意味着它会在内部重定向到
    /index.php?\u url=/address/
    ,并反复进入
    try\u文件

  • 因此,它可能比使用
    try_files$uri$uri/@rewrite
    您实际上需要使用
    try\u files$uri$uri//index.php?\u url=$request\u uri
    并将
    location@php
    更改为
    location~\.php$

    以下是我用于Laravel站点的Nginx设置

    server {
        listen 80;
        listen [::]:80 ipv6only=on;
    
        server_name SITE_URL;
    
        access_log      /var/log/nginx/access.log;
        error_log       /var/log/nginx/error.log;
        rewrite_log     on;
        access_log      on;
    
        root WEB_ROOT;
    
        index index.php;
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
    
        # Remove trailing slash.
        if (!-d $request_filename) {
            rewrite     ^/(.+)/$ /$1 permanent;
        }
    
        location ~* \.php$ {
            fastcgi_pass                unix:/var/run/php5-fpm.sock;
            fastcgi_index               index.php;
            fastcgi_split_path_info     ^(.+\.php)(.*)$;
            include                     /etc/nginx/fastcgi_params;
            fastcgi_param               SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    
        # We don't need .ht files with Nginx.
         location ~ /\.ht {
             deny all;
         }
    }
    

    谢谢它正在工作,但我有一个新错误:[crit]25475#0:*1 stat()“/var/www/decoder now/public/”失败(13:拒绝权限)[error]25475#0:*1 connect()在连接到上游时失败(111:拒绝连接),客户端:127.0.0.1,服务器:decoder.lan,请求:“GET/HTTP/1.1”,上游:fastcgi://127.0.0.1:9001"我尝试将端口:9000更改为9001,但它不再工作,我尝试从/var/run/php5-fpm.sock开始,它的错误again@Roman确保使用
    用户www数据,并且php fpm正在正确的端口上侦听(对于TCP,请检查
    netstat-lntp
    ,对于Unix套接字,请检查
    netstat-lnxp
    )。是的,我使用www数据。nginx.conf的第1行-用户www数据;关于右端口:我返回到/var/run/php5-fpm.sock,因为在
    netstat-lnxp
    中可以找到它,谢谢!它正在工作,但我有一个新错误:[crit]25475#0:*1 stat()“/var/www/decoder now/public/”失败(13:拒绝权限)[error]25475#0:*1 connect()在连接到上游时失败(111:拒绝连接),客户端:127.0.0.1,服务器:decoder.lan,请求:“GET/HTTP/1.1”,上游:fastcgi://127.0.0.1:9001"我尝试将端口:9000更改为9001,但它无法正常工作。我通常会将nginx用户添加到www数据组。这可能会解决您的权限问题。使用这个命令:sudo usermod-a-G www data nginx同样,如果您的php.ini设置为使用IP地址,您需要更新我的配置文件中的fastcgi_pass行,因为它使用的是unix sock。我没有nginx用户,对吗?我必须创建他?在服务器上安装Nginx应该创建用户。