2016-04-29 53 views
0

我試圖設置一個AWS Ubuntu服務器來託管Laravel項目。我遇到了路由問題,我懷疑我的Nginx虛擬主機配置文件是罪魁禍首。Laravel 5.2和PHP 7的Nginx配置:路由不工作

我認爲具體try_files線是問題?我試過try_files $uri $uri/ /index.php$is_args$args;以及try_files $uri $uri/ /index.php?$query_string;,以及其他幾個人,有幾個錯誤的結果,其中包括:

  • 404錯誤
  • 500錯誤
  • 被連接到一個下載源代碼
  • 它是當前的行爲,被重定向到/index.php/(顯示Laravel歡迎頁面)。

這裏是我的/ etc/nginx的/啓用的站點 - /默認:

server { 
    listen 80 default_server; 
    listen [::]:80 default_server ipv6only=on; 

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

    # Make site accessible from amazon aws 
    server_name xxxx.us-west-2.compute.amazonaws.com; 

    location/{ 
      # Try file, then try folder, then pass to Laravel's /public/index.php 
      try_files $uri $uri/ /index.php$is_args$args; 
    } 

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
    location ~ \.php$ { 
      fastcgi_split_path_info ^(.+\.php)(/.+)$; 
      # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini 

      try_files $uri /index.php =404; 
      fastcgi_split_path_info ^(.+\.php)(/.+)$; 
      fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; 
      fastcgi_index index.php; 
      include fastcgi_params; 
    } 
} 

這是文件的當前狀態,就像我說的,它目前重定向任何真正的航線blahblah.com/index.php/和顯示器Laravel的歡迎頁面。尚未設置的虛擬路由將導致Laravel 404頁面。

我很難過,因爲有幾個指南,我已經嘗試了所有的建議,我可以找到,所以我必須失去一些東西。

它會出現php7工作正常,不是問題,或者這可能是一個PHP配置文件中的問題?

DEVELOPMENTS: 它似乎正常工作,如果我訪問該網站使用其IP(感謝奧利弗女王),任何想法如何使我在使用域名時可以工作?

回答

4

與下面的代碼替換當前的location /

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

然後用替換它下面的位置:

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

就像我說的,試過選擇了。儘管我會幽默。更改了文件'sudo service nginx restart',重新加載頁面,沒有改變行爲。 – aurath

+0

對不起@aurath,我提交過早 – Derek

+0

請再試一次以上 – Derek