2017-06-14 51 views
0

PHP 7路線這是我的配置Laravel 5.4 Nginx的1.10,除了「/」正在返回404

server { 
    listen 80; 
    listen [::]:80; 

    server_name mysite.com; 

    root /var/www/site/public; 
    index index.php index.html; 

    location/{ 
      try_files $uri $uri/ /index.php$is_args$args; 
    } 

    location ~ \.php$ { 
      try_files \$uri /index.php =404; 
      fastcgi_split_path_info ^(.+\.php)(/.+)\$; 
      fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
      fastcgi_index index.php; 
      fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name; 
      include fastcgi_params; 
    } 
} 

我的網站的根訪問,其他所有路由都返回404錯誤。

在此先感謝。

乾杯。

回答

0

我不知道有什麼區別,但我刪除了配置文件和所作的默認配置的副本,更改了我需要的線路。 (即server_name,root)

它開始工作。

0

一些變化......我運行PHP 7.1 ...

位置...嘗試/index.php?$query_string;如下面的例子...

server { 
    listen 80; 
listen [::]:80; 

server_name mysite.com; 

root /var/www/site/public; 
index index.php index.html; 



index index.html index.htm index.php; 

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



    error_page 404 /index.php; 

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

} 
+0

嗨,謝爾,謝謝你的回答,但它不工作.. –

0

確保您PHP-FPM運行相同的用戶nginxsudo vim /etc/php/7.1/fpm/pool.d/www.conf

... 
user = nginx 
group = nginx 
... 
listen.owner = nginx 
listen.group = nginx 
... 

然後sudo systemctl restart php7.1-fpm.service

這是我的配置。

server { 
    listen 80; 

    root /home/user/projects/apple/public; 
    index index.php index.html index.htm; 

    server_name apple.dev; 

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

    location ~ \.php$ { 
     try_files $uri /index.php =404; 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass unix:/run/php/php7.1-fpm.sock; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include fastcgi_params; 
    } 
}