2014-11-24 46 views
1

我試圖設置我的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; 
    } 

    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" 

這個例子與網址的工作:decoder.lan /地址,但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數據的用戶,因爲在/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 

在這個實例中,我曾經工作過Apache服務器,但他在這一刻斷電了。所有請求都在nginx服務器上。

請幫助我,我的英語不好:)

回答

1

這裏是Nginx的設置我使用Laravel網站。

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

謝謝!它的工作,但我有新的錯誤:[暴擊] 25475#0:* 1 stat()「/ var/www /解碼器 - 現在/公共/」失敗(13:權限被拒絕)[錯誤] 25475#0:* 1 connect()失敗(111:連接被拒絕),同時連接到上游,客戶端:127.0.0.1,server:decoder.lan,請求:「GET/HTTP/1.1」,上游:「fastcgi://127.0.0.1:9001」我嘗試更改端口:9000到9001,但它不再工作 – Roman 2014-11-24 14:20:02

+0

我通常將nginx用戶添加到www數據組。這可能會解決您的權限問題。使用此命令:sudo usermod -a -G www-data nginx – 2014-11-24 14:22:39

+0

此外,如果您的php.ini設置爲使用IP地址,則需要更新配置文件中的fastcgi_pass行,因爲它使用的是unix sock。 – 2014-11-24 14:23:46

0

第一件事情對不起,你似乎有人權問題,檢查什麼是用戶nginx的工作進程與(用戶指令)運行。

第二件事,你的@php@handler位置永遠不會到達。

第三件事,你的try_files指令負責產生一個內部重定向週期。簡單地舉一個例子URL,並採取時間去想什麼nginx的就可以了:

  1. 你打http://decoder.lan/address/
  2. 的嘗試文件指令將相當於在運行時try_files /address/ /address// @rewrite;
  3. @rewrite命名的位置將導致重寫的URI:/index.php?_url=/address/
  4. 未指定重寫指令標誌時的默認行爲是使用last標誌,這意味着它在內部重定向到/index.php?_url=/address/並一次又一次地返回the try_files

所以很可能比不使用try_files $uri $uri/ @rewrite;您真正需要使用try_files $uri $uri/ /index.php?_url=$request_uri;和更改location @phplocation ~\.php$

+0

謝謝!它正在工作,但我有新的錯誤: [暴擊] 25475#0:* 1 stat()「/ var/www/decoder-now/public /」失敗(13:權限被拒絕) [error] 25475#0 :連接上游時,* 1 connect()失敗(111:連接拒絕),client:127.0.0.1,server:decoder.lan,請求:「GET/HTTP/1.1」,上游:「fastcgi://127.0.0.1 :9001「 我嘗試更改端口:9000到9001,但它不再工作 – Roman 2014-11-24 13:52:45

+0

,我嘗試啓動/var/run/php5-fpm.sock,再次出現錯誤 – Roman 2014-11-24 14:02:07

+0

@Roman請確保您使用'user www- data;'在nginx.conf中,並且php-fpm正在偵聽正確的端口(對於Unix套接字,請檢查netstat -lntp是否爲TCP或netstat -lnxp)。 – 2014-11-24 15:27:55