我有一些包含缓存清除字符串的 URL。我想重写这些不含缓存清除字符串的 URL,然后将符合特定条件(例如音频/视频文件)的重写 URL 发送到 PHP 脚本。
例如
/style.1233333555.css => /style.css
/video.3232474527.mp4 => /video.mp4 => /index.php
以下是我目前所掌握的信息:
server {
listen 80 default_server;
server_name _;
#force all traffic to be encrypted
return 301 https://xyz.com$request_uri;
}
server {
listen 443 ssl;
server_name xyz.com;
ssl on;
ssl_session_timeout 5m;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
ssl_prefer_server_ciphers on;
ssl_certificate /etc/nginx/ssl/xyz.com.crt;
ssl_certificate_key /etc/nginx/ssl/xyz.com.key;
root /srv/xyz.com;
index index.php;
#for all files in the format "name.0000000.ext" e.g. "child.3126043152.jpg"
location ~ (.*\/)?([^/]+)\.[a-zA-Z0-9]+(@2x)?\.([^\.]+)$ {
#cache the files for as long as possible
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
#remove the cache busting string and rewrite to the file's actual url
rewrite (.*\/)?([^/]+)\.[a-zA-Z0-9]+(@2x)?\.([^\.]+)$ $1$2$3.$4 last;
}
#pass media files through index.php so we can duplicate the actual file
rewrite \.(mp3|mp4|m4v|avi)$ /index.php;
#specify which files we can X-Accel-Redirect to
location /media {
internal;
alias /srv/xyz.com;
}
#pass anything that doesn't exist through index.php
location / {
try_files $uri $uri/ /index.php;
}
#tell nginx how to handle PHP files
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
此配置不会产生任何错误,但不会将音频/视频转发到 PHP 脚本。
我究竟做错了什么?
谢谢。