缘由

很久不使用apache了,渐渐对apache感到陌生,因为朋友有个zendframework框架从apache移到nginx下,需要pathinfo模式支持。

网上海搜

于是开始搜索nginx+pathinfo相关文章,一开以为很容易就会配置好。因为搜索后发现有大量文章介绍nginx开启pathinfo模式,感觉不是什么难事。但是经过几个小时下来,还是没有配置好。并且大量文章的内容都极其相似,基本都是转载的。
开始有点急了!因为一天过去了没有配好。

继续摸索

没办法,继续搜索。为了验证方便,我用a.com下载thinkphp框架搭了个环境。并且加了useraction.class.php控制器类,在类里加了一个app方法并输出一行文字。
于是,我开始不断地改写nginx.conf文件重启nginx,不断的刷新a.com/index.php/user/app 地址。结果要么是地址损坏提示、502、access defind.
又是一天过去了,开始感觉有点彷徨。

最后坚持

按理说我感觉应该有nginx+thinkphp的先例,只是我没有搜索到答案而已。突然间感觉网上好迷茫,一个小小的问题寻求不到解答。今晚,又试着使用nginx thinkphp关键字搜索,我一下点到十多页以后,找到一处代码

复制代码 代码如下:

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,刷新浏览器
意想不到的页面出现了

nginx中怎么配置pathinfo模式-LMLPHP

居然能访问了,终于松了一口气,实在太不容易了。
贴出nginx.conf代码:

复制代码 代码如下:

user www www;
worker_processes 2;
worker_cpu_affinity 01 10;

error_log /data1/logs/nginx_error.log crit;

pid /usr/local/webserver/nginx/nginx.pid;

worker_rlimit_nofile 65535;

events
{
use epoll;
worker_connections 65535;
}

http
{
include mime.types;
default_type application/octet-stream;

server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;

sendfile on;
tcp_nopush on;

keepalive_timeout 60;
tcp_nodelay on;

fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;

server
{
listen 80;
server_name a.com;
index index.php;
root /data0/htdocs/a.com/www;

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中怎么配置pathinfo模式的详细内容,更多请关注Work网其它相关文章!

09-19 08:12