| 
 | 
 
在apache下用thinkphp做了一个项目 倒腾的差不多了,就上传到服务器中测试,结果发现服务器是用的nginx,TP中的模板替换__PUBLIC__在其他页面中会解析出错,网上了解到是因为nginx的pathinfo是默认没有设置的 
为了调试,下午在win下装了一个nginx 
如果电脑上已安装过apache,请把它的端口改一下,不要让它与nginx冲突,打开AppServ/Apache2.2/conf/httpd.conf修改67行Listen 80  我改为8080 可以改成任意空闲的端口 
然后打开windows下的php.ini文件把476行enable_dl = On前面的分号去掉 
然后检查下AppServ\php5\ext下有没有一个叫php_redis.dll的文件,没有的话下载一个相同版本的扩展文件,并且在php.ini中打开注释601行 
  
这些条件都弄好之后 ,我们可以进行一下的操作 ,首先下载一个nginx放到一个文件夹下取名为nginx 
打开我们nginx的配置文件 
 
#location ~ \.php$ { 
 
#    
root           
html; 
 
#    fastcgi_pass   127.0.0.1:9000; 
 
#   fastcgi_index  index.php; 
 
#    fastcgi_param  SCRIPT_FILENAME   
C:/AppServ/www/$fastcgi_script_name; 
 
#   include        
fastcgi_params; 
 
#  } 
 
 
找到这一段 替换成 
 
location ~* \.(php[3-9]?|phtm[l]?)(\/.*)*$ { 
 
fastcgi_index index.php; 
 
fastcgi_pass 127.0.0.1:9000; 
 
include fastcgi_params; 
 
set $path_info ""; 
 
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 
C:/AppServ/www/$fastcgi_script_name; 
 
fastcgi_param SCRIPT_NAME $real_script_name; 
 
fastcgi_param PATH_INFO $path_info; 
 
} 
 http://www.server110.com/ 
我的所有配置都在这里 不妨给大家做个参考nginx全部配置 
#user  nobody; 
worker_processes  1; 
#error_log  logs/error.log; 
#error_log  logs/error.log  notice; 
#error_log  logs/error.log  info; 
#pid       logs/nginx.pid; 
events { 
worker_connections  1024; 
} 
http { 
include       mime.types; 
default_type  application/octet-stream; 
#log_format  main  '$remote_addr - $remote_user[$time_local] "$request" ' 
#                 '$status $body_bytes_sent "$http_referer" ' 
#                 '"$http_user_agent" "$http_x_forwarded_for"'; 
#access_log  logs/access.log  main; 
sendfile        on; 
#tcp_nopush     on; 
#keepalive_timeout  0; 
keepalive_timeout  65; 
#gzip  on; 
server { 
listen       80; 
server_name  127.0.0.1; 
#charset koi8-r; 
#access_log  logs/host.access.log  main; 
location / { 
root   C:/AppServ/www; 
index  index.html index.htm index.php; 
} 
#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; 
#} 
#location ~ \.php$ { 
#        proxy_pass  http://192.168.1.208:8001; 
#} 
# pass the PHP scripts to FastCGI server listening on127.0.0.1:9000 
# 
 
#location ~ \.php$ { 
 
#    
root           
html; 
 
#    fastcgi_pass   127.0.0.1:9000; 
 
#   fastcgi_index  index.php; 
 
#    fastcgi_param  SCRIPT_FILENAME   
C:/AppServ/www/$fastcgi_script_name; 
 
#   include        
fastcgi_params; 
 
#  } 
 
 
 
location ~* \.(php[3-9]?|phtm[l]?)(\/.*)*$ { 
 
fastcgi_index index.php; 
 
fastcgi_pass 127.0.0.1:9000; 
 
include fastcgi_params; 
 
set $path_info ""; 
 
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 
C:/AppServ/www/$fastcgi_script_name; 
 
fastcgi_param SCRIPT_NAME $real_script_name; 
 
fastcgi_param PATH_INFO $path_info; 
 
} 
 
 
# deny access to .htaccess files, if Apache's document root 
# concurs with nginx's one 
# 
#location ~ /\.ht { 
#    deny  all; 
#} 
} 
# another virtual host using mix of IP-, name-, and port-basedconfiguration 
# 
#server { 
#    listen      8000; 
#    listen      somename:8080; 
#    server_name  somename  alias another.alias; 
#    location / { 
#        root  html; 
#        index  index.htmlindex.htm; 
#    } 
#} 
# HTTPS server 
# 
#server { 
#    listen      443; 
#    server_name  localhost; 
#   ssl                 on; 
#    ssl_certificate     cert.pem; 
#    ssl_certificate_key  cert.key; 
#    ssl_session_timeout  5m; 
#    ssl_protocols  SSLv2 SSLv3 TLSv1; 
#    ssl_ciphers  HIGH:!aNULL:!MD5; 
#    ssl_prefer_server_ciphers   on; 
#    location / { 
#        root  html; 
#        index  index.htmlindex.htm; 
#    } 
#} 
} 
  
此时差不多配置好了那么我们运行PHP要借助一个AppServ\php5下叫php-cgi.exe文件 
那么我们怎么用它呢?有一段命令 
cd到你appserv在的盘符 
cd AppServ/php5/ 
start php-cgi.exe -b 127.0.0.1:9000 -C c:\windows\php.ini 
执行上面这段话,成功的话,会跳出一个黑色的窗口,我们不要去动它,如果想省事的话,写一个.bat文件 
 
C: 
 
cd AppServ/php5/ 
 
start php-cgi.exe -b 127.0.0.1:9000 -C c:\windows\php.ini 
 
 
然后开启我们的nginx 
cd 到nginx目录下 
start nginx 
nginx -s reload      //然后重载一下配置文件 
我们写两个.bat文件 一个是开启  一个是停止 
  
stop_nginx.bat 
 
@echo off 
 
echo Stopping nginx... 
 
taskkill /F /IM nginx.exe > nul 
 
echo Stopping PHP FastCGI... 
 
taskkill /F /IM php-cgi.exe > nul 
 
exit 
 
 
  
start_nginx.bat 
  
 
@echo off 
 
echo Starting PHP FastCGI... 
 
RunHiddenConsole e:/DedeCMS/PHP5/php-cgi.exe -b 127.0.0.1:9000 
-c e:/DedeCMS/PHP5/php.ini 
 
echo Starting nginx... 
 
RunHiddenConsole e:/DedeCMS/nginx.exe 
 
Exit 
 
 
  
以上配置完成之后 ,thinkphp就不会出现路径问题了 |   
 
 
 
 |