I have old configuration with apache. Now i want to reconfigurate everything to nginx+php-fpm. But have some problems with SCRIPT_FILENAME. My project stores in folder /www. It have 3 folderis in it.
- 1st folder for static images. (img) Should work on site.com/images/[1.png]
- 2nd folder for custom php scripts (php) Sloud work on site.com/php/[qweqwe]
- 3rd foled for Yii project.(yii) Should work on site.com/yii/
They have custom rewrites.
Here my nginx server config:
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;
}
}
But every time i have error
FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream
I already made it) With help Thanks steve klein. My final config: