企业实战项目Linux+nginx+php+mysql+redis部署web服务2.0

由于公司开发使用的是thinkphp框架,之前文档的nginx配置无法很好的支持。

如果你也遇到这个问题那么将你的nginx.conf修改为如下

注意:以下配置加在 server{}中


location "/"的配置

location / {
                        root html;
                        index index.php index.html index.htm;
                        if (!-e $request_filename) {
                                rewrite ^(.*)$ /index.php?s=$1 last;
                                break;
                        }
                }

fastcgi配置

注意:如果你的fastcgi配置,location匹配写的是    location ~ \.php$,需要把"$"去掉

                location ~ \.php {
                        root html;
                        fastcgi_pass 127.0.0.1:9000;
                        fastcgi_index index.php;                   
                        fastcgi_cache cache_fastcgi;
                        fastcgi_cache_valid 200 302 1h;
                        fastcgi_cache_valid 301 1d;
                        fastcgi_cache_valid any 1m;
                        fastcgi_cache_min_uses 1;
                        fastcgi_cache_use_stale error timeout invalid_header http_500;
                                                set $real_script_name $fastcgi_script_name;    
                                                if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {    
                                                set $real_script_name $1;    
                                                set $path_info $2;    
                                                }
                                                fastcgi_cache_key http://$host$request_uri;
                                                fastcgi_split_path_info ^(.+\.php)(.*)$;
                                                fastcgi_param PATH_INFO $fastcgi_path_info;
                                                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                                                include fastcgi_params;
                }