nginx开启对伪静态隐藏index.php的支持

时间:2017-06-21 23:34:12 类型:PHP
字号:    

最近看到人有说某个PHP框架不支持nginx, 这应该是一个理解的错误, 既然是PHP框架, 肯定是用PHP程序写的, 而nginx就是运行PHP的WEB服务器, 所以, 只能说一些配置与apache来比, 有一些区别, 但绝对不会说某个框架在APACHE下OK, 但在nginx是不不行的

这里贴下nginx下对伪静态的支持, 从而来隐藏index.php文件, 在nginx的配置文件或者加载的vhosts.conf文件里面增加

server {
        listen       80;
        server_name  ncdzsj.cn phpStudy.net;
        root   "D:/phpStudy/WWW/ncdzsj.cn";
        location / {
            index  index.html index.htm index.php;
            rewrite ^/$ /index.php last;  #增加这一行
            rewrite ^/(?!index\.php|robots\.txt|images|js|up|css)(.*)$ /index.php/$1 last;  #增加这一行
            #autoindex  on;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}