/ 中存储网

ThinkPHP框架下在Nginx服务器的配置问题

2013-08-17 21:50:00 来源:ITJS.CN
前几天看到同事在我的机器上在nginx服务器下配置一个本地访问的网站,而那个站是以用ThinkPHP框架为基础构建的。结果按照最开始的配置方法(就是nginx默认的配置方法)配置这个站,怎么多访问不了。。。难道是这个服务器不支持ThinkPHP框架。。在网上查了查资料发现果然用了thinkphp框架的网站在该服务器下不能简单的按照它默认的方式去配置需要在配置里面加一些代码,下面是nginx服务器下两种情况的配置

没有用ThinkPHP框架在nginx中的配置:

server {

listen 80;

server_name zx.server110.com;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {

root d:/webroot/zx.server110.com;

index index.html index.htm;

}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ .php$ {

# proxy_pass http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location ~ .php$ {

root d:/webroot/zx.server110.com;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

#location ~ /.ht {

# deny all;

#}

}

用ThinkPHP框架在nginx中的配置:

server {

listen 80;

server_name user.server110.com;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {

root d:/webroot/user.server110.com;

index index.php;

if (!-e $request_filename)

{

rewrite ^/user.server110.com/(.*)$ /user.server110.com/index.php/$1 last;

break;

}

}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ .php$ {

# proxy_pass http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location ~ .+.php($|/)

{

root d:/webroot/user.server110.com;

set $script $uri;

set $path_info "/";

if ($uri ~ "^(.+.php)(/.+)")

{

set $script $1;

set $path_info $2;

}

fastcgi_pass 127.0.0.1:9000;

include fastcgi.conf;

fastcgi_index index.php?IF_REWRITE=1;

fastcgi_param PATH_INFO $path_info;

fastcgi_param SCRIPT_FILENAME $document_root/$script;

fastcgi_param SCRIPT_NAME $script;

}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

#location ~ /.ht {

# deny all;

#}

}

这两种配置中不同的地方就是新加的代码。