项目配置:
server { listen 807;server_name localhost; root /data/web/myblog/web; client_max_body_size 501m; error_log /data/server/nginx/symfony2.error.log; access_log /data/server/nginx/symfony2.access.log; # strip app.PHP/ prefix if it is present # 如果出现192.168.1.53:807/app.php/blog/index 那么直接重定向到 192.168.1.53:807/blog/index rewrite ^/app\.php/?(.*)$ /$1 permanent;
# 上面重定向后 符合到这个location 那么又进行try_files 找这个uri 如果找到直接返回uri 找不到重定向到 rewriteapp 这个loacation 进行重写 又再次变成 #192.168.1.53:807/app.php/blog/index location / { index index.php; try_files $uri @rewriteapp; } location @rewriteapp { rewrite ^(.*)$ /app.php/$1 last; } # pass the PHP scripts to FastCGI server from upstream phpfcgi location ~ ^/(app|app_dev|config)\.php(/|$) { fastcgi_pass unix:/tmp/php.sock; fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi.conf; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTPS off; } location ~ \.php$ { fastcgi_pass unix:/tmp/php.sock; fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi.conf; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTPS off; }
解析 fastcgi_split_path_info
目的:让php能够解析类似这样的url http://www.it.net.cn/index.php/abc/def
重启nginx服务
当nginx处理http://www.it.net.cn/index.php/abc/def请求时,将会把"index.php"做为php的脚本,/abc/def做为index.php脚本的参数提交给php-cgi执行 |