2017-09-15 119 views
1

我覺得我有點迷路了。現有的Apache .htaccess到Nginx配置

我嘗試了一些解決方案,但我沒有得到一個部分。一切都必須由index.php處理,我不能讓它在nginx中工作。我一直在學習Nginx,但真的很感謝某些人的快速幫助。

我的.htaccess:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?_route_=$1 [L,QSA] 

我的Nginx的配置是:

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

     root /folder; 
     index index.php index.html index.htm index.nginx-debian.html; 

     server_name hostname.com; 

     location/{ 
     try_files $uri $uri/ =404; 
      } 

    location ~ \.php$ { 
     try_files = $uri @missing; 
     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; 
    } 
     location @missing { 
      rewrite^$scheme://$host/index.php permanent; 
} 
} 

有人可以點我朝着正確的方向?謝謝

+0

以及究竟是你的問題?什麼「沒有得到它的工作」是什麼意思?請閱讀:https://stackoverflow.com/help/mcve –

+0

嘿Maciej, 我的不好。我有我的客戶想要在他們的新nginx服務器上擁有的舊cms。問題是應用程序使用工作,所以它採取whatever.php「任何」,並將其用作動態標題。所以PHP應用程序讀取index.php作爲主頁。其他任何東西都是作爲標題,並且有針對特定頁面內容的mysql查詢。 – user8614226

+0

請編輯您的原始問題與所有這些細節。確保你清楚地說明問題並提出不希望的和期望的效果。 –

回答

0

任何不以.php結尾的URI都由location /塊處理。如果你想實施你的Apache .htaccess規則,那就是它應該完成的地方。有關更多信息,請參見this document

例如:

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

location ~ \.php$塊,你應該警惕passing uncontrolled requests to PHP,例如:

location ~ \.php$ { 
    try_files $uri =404; 
    ... 
} 
+0

嗨Richard, 感謝您的回覆。在我來到stackoverflow.com之前,我嘗試了aboe解決方案。它仍然不起作用。這是一個古老的網站,但PHP函數真的是舊式的,但設計是固定的,並且CLiens想要保留所有東西。但它是在Apache上。我測試了它的工作原理,無論this-here.php將成爲頁面的標題,就像學校的動態標題一樣。目前,我仍然是這樣,hostname.com目前無法處理這個請求。 HTTP錯誤500 – user8614226