【发布时间】:2015-08-28 14:59:17
【问题描述】:
我有 apache 的旧配置。现在我想将所有内容重新配置为 nginx+php-fpm。但是 SCRIPT_FILENAME 有一些问题。 我的项目存储在文件夹 /www 中。里面有3个文件夹。
- 静态图像的第一个文件夹。 (img) 应该在 site.com/images/[1.png] 上工作
- 用于自定义 php 脚本 (php) 的第二个文件夹在 site.com/php/[qweqwe] 上运行良好
- Yii 项目的第 3 档。(yii) 应该在 site.com/yii/ 上工作
他们有自定义重写。
这里是我的 nginx 服务器配置:
server {
listen 80;
server_name site.com;
root /www;
location ~* .(js|css|png|jpg|jpeg|gif|ico|xml|swf|flv|eot|ttf|woff|pdf|xls|htc|html)$ {
add_header Pragma "public";
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
log_not_found off;
expires 360d;
}
location /php {
root /www/php;
if (!-e $request_filename){
rewrite ^(.*)$ /php/api2.php;
}
location ~* \.php$ {
#rewrite ^/(.*)/$ /$1 permanent;
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_pass pool;
}
}
location /yii {
root /www/yii;
rewrite (.*)\.small\.([^\.]+)$ /sfad/thumb.php?img=$1.$2 break;
rewrite agent[0-9]+site[0-9]+[a-z]*/(.*) /$1;
location ~* \.php$ {
#rewrite ^/(.*)/$ /$1 permanent;
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_pass pool;
}
try_files $uri /index.php?$args;
}
}
但每次我都有错误
FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream
【问题讨论】:
-
我不确定,但那些嵌套的位置块似乎是个坏主意。如果您还没有这样做,我建议您阅读这些NGINX troubleshooting tips。这真的帮助我加快了
NGINX的速度。此外,您可能希望创建一个非常简单的服务器块,验证它是否适用于您的一个用例,然后从那里扩展。 -
将文档根目录更改为真实路径。将此行
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;更改为fastcgi_param SCRIPT_FILENAME /www$fastcgi_script_name;
标签: php nginx yii rewrite stderr