nginx訪問php配置,thinkphp5配置nginx访问
thinkphp采用pathinfo模式;不像laravel和yii配置上去直接就可以干;
測試了兩個不同方式的nginx安裝 yum 和lnmp一鍵安裝包;
一鍵安裝包里面有對pathinfo的支持
下面是配置
一鍵安裝包安裝的lnmp centos7server
{
listen?8080?default_server;
#listen?[::]:80?default_server?ipv6only=on;
server_name?_;
index?index.html?index.htm?index.php;
root??/var/www/html/ibjson;
#error_page???404???/404.html;
#?Deny?access?to?PHP?files?in?specific?directory
#location?~?/(wp-content|uploads|wp-includes|images)/.*\.php$?{?deny?all;?}
include?enable-php.conf;
location?/nginx_status
{
stub_status?on;
access_log???off;
}
location?~?.*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires??????30d;
}
location?/?{
if?(!-e?$request_filename){
rewrite?^/(.*)$?/index.php?s=/$1?last;
}
}
location?~?.*\.(js|css)?$
{
expires??????12h;
}
location?~?/.well-known?{
allow?all;
}
location?~?/\.
{
deny?all;
}
access_log??/home/wwwlogs/access.log;
}
nginx端口轉發的配置如下server{
listen??????8089;
server_name?_;
root???????????/var/www/html/tp5/public;
index?index.php?index.html?index.htm;
location?~?\.php/?.*?{
fastcgi_pass???127.0.0.1:9000;
fastcgi_index??index.php;
fastcgi_param??SCRIPT_FILENAME??$document_root$fastcgi_script_name;
include????????fastcgi_params;
#定義變量?$path_info?,用于存放pathinfo信息
set?$path_info?"";
#定義變量?$real_script_name,用于存放真實地址
set?$real_script_name?$fastcgi_script_name;
#如果地址與引號內的正則表達式匹配
if?($fastcgi_script_name?~?"^(.+?\.php)(/.+)$")?{
#將文件地址賦值給變量?$real_script_name
set?$real_script_name?$1;
#將文件地址后的參數賦值給變量?$path_info
set?$path_info?$2;
}
#配置fastcgi的一些參數
fastcgi_param?SCRIPT_FILENAME?$document_root$real_script_name;
fastcgi_param?SCRIPT_NAME?$real_script_name;
fastcgi_param?PATH_INFO?$path_info;
}
location?/?{
if?(!-e?$request_filename){
rewrite?^/(.*)$?/index.php/$1?last;
}
#try_files?$uri?$uri/?/index.php?$query_string;
}
}
location?~?\.php(.*)$?{
fastcgi_pass???127.0.0.1:9001;
fastcgi_index??index.php;
fastcgi_split_path_info??^((?U).+\.php)(/?.+)$;
fastcgi_param??SCRIPT_FILENAME??$document_root$fastcgi_script_name;
fastcgi_param??PATH_INFO??$fastcgi_path_info;
fastcgi_param??PATH_TRANSLATED??$document_root$fastcgi_path_info;
include????????fastcgi_params;
}
總結
以上是生活随笔為你收集整理的nginx訪問php配置,thinkphp5配置nginx访问的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php如何防止超发,PHP+redis实
- 下一篇: 微擎css使用php变量,$_Wamp;