本文目錄一覽:
- 1、linux nginx 無法執行php文件
- 2、nginx 不能解析php怎麼辦
- 3、nginx 不支持PHP了,請問為什麼
- 4、nginx下怎麼支持THinkPHP
- 5、如何快速解決nginx不支持ThinkPHP
linux nginx 無法執行php文件
為以前沒有接觸過nginx ,所以查了一天,查處原因有二:
一、網站根目錄
默認是在 /usr/local/nginx/html文件
配置在
location / {
root /home/www/wwwroot;
index index.html index.htm;
}
二、修改文件中對應的php配置部分
location ~ \.php$ {
root /home/www/wwwroot;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
特別需要注意的是:fastcgi_param這個參數默認的是$fastcgi_script_name;最好改為$document_root$fastcgi_script_name;我在實際配置中出現了php找不到需要解析文件而返回404或者500錯誤的問題。所以最好是帶上網站根目錄的路徑變量$document_root
nginx 不能解析php怎麼辦
nginx 不能解析php解決方法如下:
在nginx配置文件中添加:
location ~ .*\.php?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
nginx 不支持PHP了,請問為什麼
請在服務器仔細排錯,重啟一下php-fcgi,仍後用netstat -untl 查看端口一切是否監聽正常
nginx下怎麼支持THinkPHP
ThinkPHP支持通過PATHINFO和URL rewrite的方式來提供友好的URL,只需要在配置文件中設置 ‘URL_MODEL’ = 2 即可。在Apache下只需要開啟mod_rewrite模塊就可以正常訪問了,但是Nginx中默認是不支持PATHINFO的,所以nginx默認情況下是不支持thinkphp的。不過我們可以通過修改nginx的配置文件來讓其支持thinkphp。
讓nginx支持pathinfo,支持thinkphp
1
我們打開nginx的配置文件,如果是想某個站點支持,請打開對應站點的配置文件
如何讓nginx支持ThinkPHP框架
2
我們注釋掉配置文件中那些被我圈出來的語句(location ~ \.php$ {……}這一段裡面的),我們將對這部分進行重寫!
如何讓nginx支持ThinkPHP框架
3
將重寫後的代碼添加進去。
如何讓nginx支持ThinkPHP框架
4
添加的代碼如下:
…………………………………..
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ “^(.+?\.php)(/.+)$”) {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}希望能幫到你,我還在後盾人線下面授培訓上課學習呢現在沒時間,有不會的可以問我,加油吧(。・ω・。)ノ♡
如何快速解決nginx不支持ThinkPHP
PATHINFO NGINX默認配置是不支持的
需要在Nginx的配置文件nginx.conf 增加它。
如:
location ~ .php {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
#pathinfo support
set $real_script_name $fastcgi_script_name;
set $path_info “”;
if ( $fastcgi_script_name ~ “^(.+?.php)(/.+)$”){
set $real_script_name $1;
set $path_info $2;
} fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
我們增加了一個if判斷
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/185059.html