我已经配置了我的nginx,以便在php抛出502错误的情况下从s3获取数据,但即使没有502错误,它也会访问所有请求的数据。
这是我的配置文件
upstream php {
server unix:/var/run/php5-fpm.sock;
}
server {
listen *:80;
server_name x.x.x.x;
root /data/www/public/;
# access_log /var/log/nginx/www.example.com.access.log main;
error_log /var/log/nginx/wf_err.log;
add_header Access-Control-Allow-Origin http://x.x.x.x;
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
log_not_found off;
}
location / {
index index.php;
try_files $uri $uri/ /index.php;
}
location @static{
add_header Access-Control-Allow-Origin *;
rewrite ^ $request_uri;
rewrite ^/assets/(.*)/(.*)\.css.* /assets/$1/$2.css break;
rewrite ^/assets/(.*)/(.*)\.js.* /assets/$1/$2.js break;
rewrite ^/assets/image.*/(.*)\.(.*).* /assets/image/$1.$2 break;
rewrite ^/assets/fonts/(.*)\.(.*).* /assets/fonts/$1.$2 break;
rewrite /story/([0-9]+)/([0-9]+)/.* /story/$1/$1_$2.html break;
rewrite /story/([0-9]+)/.* /story/$1/$1_1.html break;
proxy_hide_header x-amz-id-2;
proxy_hide_header x-amz-request-id;
proxy_pass http://bucket.s3.amazonaws.com;
}
location ~ \.php {
try_files $uri =404;
fastcgi_pass php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
error_page 502 504 503 @static;
fastcgi_intercept_errors on;
# return 502;
}
# deny access to .htaccess files
location ~ /\.ht {
deny all;
}
}
我使用fastcgi_intercept_errors来捕获php发送的错误。 然后,使用error_page指令,我将位置更改为@static,从s3处理请求。
但我无法理解为什么即使没有错误,所有请求都会转到s3。
感谢。