简体   繁体   中英

setup laravel for nginx (error with permission denied)

i trying setting my laravel for nginx. My config:

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

}

I get error in 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"

this example work with url: decoder.lan/address, but decoder.lan/ not working too.

access.log file:

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"

i tried check work listen or not this file. I check this by command from console:

sudo -u www-data cat index.php

from console file was opened.

i use www-data user, because in /ect/php5/fpm/pool.d/www.conf i have:

listen.owner = www-data
listen.group = www-data
listen.mode = 0660

file list in .../decoder-now/public/ folder:

-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

on this instance, i have worked apache server, but he is power off in this moment. All request go on nginx server.

help me please, sorry for my bad english :)

Here is the Nginx setup I use for Laravel sites.

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

First thing, you seem to have rights issues, check what's user nginx worker processes are running with (user directive).

Second thing, your @php and @handler locations are never reached.

Third thing, your try_files directive is responsible for producing an internal redirection cycle. Simply take an example URL and take time to think about what nginx will do :

  1. You hit http://decoder.lan/address/
  2. The try files directive will be equivalent at runtime to try_files /address/ /address// @rewrite;
  3. The @rewrite named location will result in the rewritten URI : /index.php?_url=/address/
  4. The default behaviour when not specified a flag to the rewrite directive is to use the last flag which means it internally redirects to /index.php?_url=/address/ and goes in the try_files again and again.

So it's likely than instead of using try_files $uri $uri/ @rewrite; you actually need to use try_files $uri $uri/ /index.php?_url=$request_uri; and change location @php to location ~\\.php$

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM