2

Добрый день, пытаюсь настроить laravel для nginx, ничего не выходит.

Конфиг:

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) (в логах адресуемся к url: decoder.lan/address, но просто 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 [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"

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"

Сам пытался проверить если ли права у www-data на чтение, проверяю с помощью команды:

sudo -u www-data cat index.php

Файл открывается.

www-data, т.к. в /ect/php5/fpm/pool.d/www.conf стоит:

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

Ну и на последок, файлы:

-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

Поменял права у index.php специально

На сервере также стоит апач, который, конечно же, сейчас выключен, соответственно 80 порт ссылается только на nginx.

Обновление

@smgladkovskiy спасибо, после того как я поменял конфиг, возникла проблема:

2014/11/24 18:37:37 [crit] 8388#0: *1 stat() "/var/www/decoder-now/public/" failed (13: Permission denied), client: 127.0.0.1, server: decoder.lan, request: "GET / HTTP/1.1", host: "decoder.lan"

FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: decoder.lan, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "decoder.lan"

@smgladkovskiy пробовал менять на IP адрес с портом - не помогает. Смотрел при помощи netstat -lnxp, находит сокет - var/run/php5-fpm.sock.

2 ответа 2

4

Рабочий пример:

server {
    listen 80;
    server_name laravel-test.localhost;
    root /home/vagrant/stuff/laravel-test/public;

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/laravel-test.localhost-error.log error;

    error_page 404 /index.php;

    sendfile off;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}
2
  • @smgladkovskiy пробовал менять на IP адрес с портом - не помогает. смотрел при помощи netstat -lnxp, находит сокет - var/run/php5-fpm.sock
    – WoWProg
    24 ноя 2014 в 15:48
  • Конфиг сайта прописан в sites-available? Директива SCRIPT_FILENAME в fastcgi_param как объявлена? Вообще, менялось ли что в конфигах nginx? 24 ноя 2014 в 17:58
0

Я пользуюсь laravel-website-configs. Все грамотно прописано, с комментариями.

С помощью этих конфигов разворачиваю проекты на дропплетах Digital Ocean без всяких проблем + использую для локально разработки под Vagrant.

1
  • Прошу прощения в модераторов, помочь хочу, а оформление страдает.
    – Viktor
    18 июн 2015 в 7:52

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.