nginx完美支持thinkphp3.2.2
2015-09-03 00:03
651 查看
第一步:配置SERVER块
server {
listen 80;
server_name www.domain.com domain.com;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
# \.php 只处理动态请求,对于静态资源请求由下面的 location匹配和处理
location ~ \.php {
root /data0/htdocs/www;
fastcgi_pass 127.0.0.1:9000;
#包含nginx服务器传递给fastcgi程序的参数,php中通过$_SERVER['参数名']可获取
include fastcgi.conf;
#定义变量$fastcgi_script_name_new赋值为$fastcgi_script_name变量
set $path_info "";
set $fastcgi_script_name_new $fastcgi_script_name;
#判断url是否是pathinfo形式的,如果是则把这个url分割成两部分,index.php入口文件之后的pathinfo部分存入$path_info变量中,剩下的部分和$document_root根目录定位index.php入口文件在文件系统中的绝对路径 .
if ($fastcgi_script_name ~* "^(.+\.php)(/.+)$" ) {
set $fastcgi_script_name_new $1;
set $path_info $2;
}
#对fastcgi.conf中的SCRIPT_FILENAME和SCRIPT_NAME fastcgi参数进行重写,目的是指定入口文件在文件系统中的绝对路径给script_filename参数,让fastcgi知道index.php文件位置。
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name_new;
fastcgi_param SCRIPT_NAME $fastcgi_script_name_new;
#定义一个新的nginx服务器传递给fastcgi的参数PATH_INFO,thinkphp需要这个入口文件index.php后的pathinfo信息
fastcgi_param PATH_INFO $path_info;
}
# 用来匹配静态资源,如果不是静态资源就重写,然后重新轮训所有的location块,由上面的location块匹配后动态处理这个请求
location / {
root /data0/htdocs/www;
index index.php index.html index.htm;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php$1 last;
}
}
}
复制代码
第二步:打开thinkphp框架的配置文件convention.php,
修改URL_MODEL=>1,采用pathinfo模式,别设置成2啊,因为nginx重写加上了index.php入口文件了,也就是最终发送到thinkphp的url是pathinfo模式的。
第三步:在浏览器输入:www.domain.com或者www.domain.com/index.php结果如下:
:)
欢迎使用 ThinkPHP!
[ 您现在访问的是Home模块的Index控制器 ]
第四步:在浏览器中输入URL时候,用pathinfo形式的url和用rewrite形式的url两者中的任何都可以,或者不用这两个框架形式的url, 用一般形式的url。例如:
pathinfo形式: http://www.domain.com/index.php/module/controler/action/参数1/值1/参数2/值2/
rewrite形式(就是不要输入入口文件了,其它的和pathinfo模式一样) http://www.domain.com/module/controler/action/参数1/值1/参数2/值2/
一般形式的url,不通过index.php入口文件启动框架,也就是不用框架 http://www.domain.com/test.php?par1=value1&par2=value2 这时候需要在/data0/htdocs/www这个目录下存在自定义的test.php文件,就可以直接访问这个php文件了。
文章转自:http://www.thinkphp.cn/topic/26657.html
server {
listen 80;
server_name www.domain.com domain.com;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
# \.php 只处理动态请求,对于静态资源请求由下面的 location匹配和处理
location ~ \.php {
root /data0/htdocs/www;
fastcgi_pass 127.0.0.1:9000;
#包含nginx服务器传递给fastcgi程序的参数,php中通过$_SERVER['参数名']可获取
include fastcgi.conf;
#定义变量$fastcgi_script_name_new赋值为$fastcgi_script_name变量
set $path_info "";
set $fastcgi_script_name_new $fastcgi_script_name;
#判断url是否是pathinfo形式的,如果是则把这个url分割成两部分,index.php入口文件之后的pathinfo部分存入$path_info变量中,剩下的部分和$document_root根目录定位index.php入口文件在文件系统中的绝对路径 .
if ($fastcgi_script_name ~* "^(.+\.php)(/.+)$" ) {
set $fastcgi_script_name_new $1;
set $path_info $2;
}
#对fastcgi.conf中的SCRIPT_FILENAME和SCRIPT_NAME fastcgi参数进行重写,目的是指定入口文件在文件系统中的绝对路径给script_filename参数,让fastcgi知道index.php文件位置。
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name_new;
fastcgi_param SCRIPT_NAME $fastcgi_script_name_new;
#定义一个新的nginx服务器传递给fastcgi的参数PATH_INFO,thinkphp需要这个入口文件index.php后的pathinfo信息
fastcgi_param PATH_INFO $path_info;
}
# 用来匹配静态资源,如果不是静态资源就重写,然后重新轮训所有的location块,由上面的location块匹配后动态处理这个请求
location / {
root /data0/htdocs/www;
index index.php index.html index.htm;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php$1 last;
}
}
}
复制代码
第二步:打开thinkphp框架的配置文件convention.php,
修改URL_MODEL=>1,采用pathinfo模式,别设置成2啊,因为nginx重写加上了index.php入口文件了,也就是最终发送到thinkphp的url是pathinfo模式的。
第三步:在浏览器输入:www.domain.com或者www.domain.com/index.php结果如下:
:)
欢迎使用 ThinkPHP!
[ 您现在访问的是Home模块的Index控制器 ]
第四步:在浏览器中输入URL时候,用pathinfo形式的url和用rewrite形式的url两者中的任何都可以,或者不用这两个框架形式的url, 用一般形式的url。例如:
pathinfo形式: http://www.domain.com/index.php/module/controler/action/参数1/值1/参数2/值2/
rewrite形式(就是不要输入入口文件了,其它的和pathinfo模式一样) http://www.domain.com/module/controler/action/参数1/值1/参数2/值2/
一般形式的url,不通过index.php入口文件启动框架,也就是不用框架 http://www.domain.com/test.php?par1=value1&par2=value2 这时候需要在/data0/htdocs/www这个目录下存在自定义的test.php文件,就可以直接访问这个php文件了。
文章转自:http://www.thinkphp.cn/topic/26657.html
相关文章推荐
- Ubuntu下 5步安装nginx记录
- nginx启动、停止、重启、配置文件校验
- nginx完全配置
- Nginx 常见应用技术指南[Nginx Tips] 第二版
- 使用nginx配置多个php-fastcgi负载均衡
- Nginx and PHP-FPM Configuration and Optimizing Tips and Tricks
- nginx 负载均衡
- nginx之nginx部署
- 使用Nginx配置NodeJs程序(Windows平台)
- 关于Nginx配置文件及ReWriteUrl那点事~
- 如何使用 Datadog 监控 Nginx
- nginx快速安装
- Ubuntu配置nginx+php
- nginx源码编译
- Nginx 在window server 2008R2上装有IIS启动不了
- 解析nginx负载均衡
- nginx使用笔记
- nginx 多个80端口转发
- centos安装php php-fpm nginx
- 开启Nginx的gzip压缩功能详解