Nginx 配置 SCRIPT_FILENAME
Nginx configuration SCRIPT_FILENAME
我对 apache 有旧的配置。现在我想将所有内容重新配置为 nginx+php-fpm。但是 SCRIPT_FILENAME 有一些问题。
我的项目存储在文件夹 /www 中。它有 3 个文件夹。
- 静态图像的第一个文件夹。 (img) 应该在现场工作。com/images/[1.png]
- 自定义 php 脚本的第 2 个文件夹 (php) 现场工作很吵。com/php/[qweqwe]
- Yii 项目第三次失败。(yii) 应该在现场工作。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 ^/(.*)/$ / 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=. break;
rewrite agent[0-9]+site[0-9]+[a-z]*/(.*) /;
location ~* \.php$ {
#rewrite ^/(.*)/$ / 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
我已经做到了) help 谢谢史蒂夫·克莱因。
我的最终配置:
server {
listen 80;
server_name site.com;
access_log /var/log/nginx/olimpic-access.log main buffer=16k;
error_log /var/log/nginx/olimpic-dev-error.log warn;
root /www;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt { access_log off; log_not_found off; }
location ~ /\. { access_log off; log_not_found off; deny all; }
location ~ ~$ { access_log off; log_not_found off; deny all; }
location ~ /.ht { deny all; access_log off; log_not_found off; }
location ~ /yii/(protected|framework|nbproject) { deny all; access_log off; log_not_found$
location ~ /yii/themes/\w+/views { deny all; access_log off; log_not_found off; }
location ~* .(js|css|png|jpg|jpeg|gif|ico|xml|swf|flv|eot|ttf|woff|pdf|xls|htc|html)$ {
rewrite (.*)\.small\.([^\.]+)$ /yii/sfad/thumb.php?img=.;
add_header Pragma "public";
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
log_not_found off;
expires 360d;
}
location ~* /yii/agent[0-9]+site[0-9]+[a-z]*/(.*) {
rewrite agent[0-9]+site[0-9]+[a-z]*/(.*) /yii/;
try_files $uri $uri/ /yii/index.php?$args;
}
location /yii/ {
try_files $uri /yii/index.php?$args;
}
location /php/ {
try_files $uri /php/api2.php;
}
location ~* \.php$ {
rewrite ^/php/(.*)$ /php/api2.php break;
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass php-workers;
}
}
我对 apache 有旧的配置。现在我想将所有内容重新配置为 nginx+php-fpm。但是 SCRIPT_FILENAME 有一些问题。 我的项目存储在文件夹 /www 中。它有 3 个文件夹。
- 静态图像的第一个文件夹。 (img) 应该在现场工作。com/images/[1.png]
- 自定义 php 脚本的第 2 个文件夹 (php) 现场工作很吵。com/php/[qweqwe]
- Yii 项目第三次失败。(yii) 应该在现场工作。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 ^/(.*)/$ / 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=. break;
rewrite agent[0-9]+site[0-9]+[a-z]*/(.*) /;
location ~* \.php$ {
#rewrite ^/(.*)/$ / 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
我已经做到了) help 谢谢史蒂夫·克莱因。 我的最终配置:
server {
listen 80;
server_name site.com;
access_log /var/log/nginx/olimpic-access.log main buffer=16k;
error_log /var/log/nginx/olimpic-dev-error.log warn;
root /www;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt { access_log off; log_not_found off; }
location ~ /\. { access_log off; log_not_found off; deny all; }
location ~ ~$ { access_log off; log_not_found off; deny all; }
location ~ /.ht { deny all; access_log off; log_not_found off; }
location ~ /yii/(protected|framework|nbproject) { deny all; access_log off; log_not_found$
location ~ /yii/themes/\w+/views { deny all; access_log off; log_not_found off; }
location ~* .(js|css|png|jpg|jpeg|gif|ico|xml|swf|flv|eot|ttf|woff|pdf|xls|htc|html)$ {
rewrite (.*)\.small\.([^\.]+)$ /yii/sfad/thumb.php?img=.;
add_header Pragma "public";
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
log_not_found off;
expires 360d;
}
location ~* /yii/agent[0-9]+site[0-9]+[a-z]*/(.*) {
rewrite agent[0-9]+site[0-9]+[a-z]*/(.*) /yii/;
try_files $uri $uri/ /yii/index.php?$args;
}
location /yii/ {
try_files $uri /yii/index.php?$args;
}
location /php/ {
try_files $uri /php/api2.php;
}
location ~* \.php$ {
rewrite ^/php/(.*)$ /php/api2.php break;
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass php-workers;
}
}