Nginx下PHP CI完全配置

CI去除链接中的index.php在Apache下设置非常简单,官网即有说明。

但是在Nginx下稍显复杂,这里给出完全配置文件。

   1: location / {

   2:    root /www/;

   3:    index index.php index.html index.htm;

   4:    if (-f $request_filename) {

   5:      expires max;

   6:      break;

   7:    }

   8:  

   9:    #if (!-e $request_filename) {

  10:    #    rewrite ^/(.*)$ /index.php/$1 last;

  11:    #}

  12:     if ($request_filename !~ (js|css|images|robots/.txt|index/.php.*) ) {

  13:         rewrite ^/(.*)$ /index.php/$1 last;

  14:         break;

  15:     }

  16:  

  17: }

  18: location ~ \.php($|/) {

  19:     root           /www;

  20:     fastcgi_pass   127.0.0.1:9000;

  21:     fastcgi_index index.php;

  22:     fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

  23:     fastcgi_param  PATH_INFO  $fastcgi_path_info;

  24:     fastcgi_split_path_info ^(.+\.php)(.*)$;

  25:     include fastcgi_params;

  26: }

  27: #error_page  404              /404.html;

  28:  

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

  30: #

  31: error_page   404 500 502 503 504  /50x.html;

  32: location = /50x.html {

  33:     root   html;

  34: }

  35:  

  36: #以下配置防范nginx图片漏洞

  37:  if ( $fastcgi_script_name ~ \.*\.(png|jpg|gif|bmp|PNG|JPG|GIF|BMP)\/.*php ) {

  38:     return 404;

  39: }

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

  41: # concurs with nginx's one

  42: #

  43: #location ~ /\.ht {

  44: #    deny  all;

  45: #}

更改配置后可以平滑重启一下:

/usr/nginx/sbin/nginx -s reload

刷新前可以检查文件是否正确。判断Nginx配置是否正确命令如下:

nginx -t -c /usr/nginx/conf/nginx.conf

发表评论

电子邮件地址不会被公开。 必填项已用*标注