我在一台RHEL服务器上并且有一个时间的野兽让我的nginx配置服务于具有缓存的WP站点。我想在nginx层处理缓存而不是使用WP插件,因为我认为它会更可靠(可能使用nginx缓存清除插件来帮助WP处理清除)。还没有找到实际在缓存上返回HIT的配置设置的组合。下面的配置 - 希望所有人都能看到我失踪的东西(我已经删除了所有的缓存配置,因为它没有工作 - 这基本上是nginx网站的直接拉动标准WP设置):
add_header Fastcgi-Cache $upstream_cache_status;
# Upstream to abstract backend connection(s) for php
upstream php {
server unix:/tmp/php-cgi.socket;
server 127.0.0.1:9000;
}
server {
listen 80;
listen [::]:80;
listen 443 ssl;
## Your website name goes here.
server_name intranet-test.*;
root /var/www/html/intranet;
index index.php index.html index.htm;
ssl_certificate /etc/httpd/conf.d/certificates/intranet-test.cer;
ssl_certificate_key /etc/httpd/conf.d/keys/intranet-test.key;
if ($scheme = http) {
return 301 https://$server_name$request_uri;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
需要添加什么才能设置nginx的缓存?
答案 0 :(得分:0)
更改
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
要
location ~* \.(?:ico|jpg|jpeg|png|gif|svg|js|css|swf)$ {
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
expires 1y;
access_log off;
}
location ~* \.(?:ttf|eot|woff|otf|woff2)$ {
add_header Access-Control-Allow-Origin "*";
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
expires 1y;
access_log off;
}