我有一台运行CentOS和Nginx /
PHP-FPM的VPS.一切正常,除非我添加以下行以启用静态缓存内容.如果我这样做,页面不会加载指定的文件以保持缓存.
location ~* \.(ico|css|js|gif|jpg|jpeg|png)${ expires 30d; add_header Vary Accept-Encoding; access_log off; }
这是我的整个服务器{}:
server { listen 80; server_name mywebsite.com www.mywebsite.com; #location ~* \.(ico|css|js|gif|jpg|jpeg|png)${ # expires 30d; # add_header Vary Accept-Encoding; # access_log off; #} location / { if ($http_host ~* "^www.(.*)$"){ set $rule_0 1$rule_0; set $bref_1 $1; } if ($rule_0 = "1"){ rewrite ^/(.*)$http://$bref_1/$1 permanent; } rewrite ^/search/(.*)/(.*)/?$/index.PHP?search=$1&page=$2&type=mp3 las$ rewrite ^/(.*)/(.*)/(.*)?$/index.PHP?search=$1&page=$2&type=$3 last; root /var/www/mywebsite.com/public_html; index index.PHP index.html index.htm; } location ~ \.PHP${ fastcgi_read_timeout 300; root /var/www/mywebsite.com/public_html; fastcgi_pass unix:/tmp/PHP5-fpm.sock; fastcgi_index index.PHP; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
有谁知道为什么?
更新(解决方案):
您的服务器块没有定义根指令.相反,它似乎位于您的一个位置块中.这是
the most common nginx mistakes之一.将其移到服务器块下.