简体   繁体   English

带有缓存的Nginx WordPress配置

[英]nginx WordPress config with caching

Am on a RHEL server and having a beast of a time getting my nginx config to serve a WP site with caching. 我在RHEL伺服器上,想让我的nginx设定来提供快取服务的WP网站,真是令人费解。 I'd like to handle caching at the nginx layer instead of futzing around with WP plugins, as I think it will be more reliable (with potentially using the nginx cache purge plugin just to help WP handle purging). 我想在nginx层处理缓存,而不是费心处理WP插件,因为我认为它将更加可靠(可以使用nginx缓存清除插件来帮助WP处理清除)。 Have yet to find a combination of config settings that actually return HITs on the cache. 尚未找到实际在缓存上返回HIT的配置设置组合。 Config below - hopefully y'all see something that I'm missing (I've stripped out all of the caching config as none of it has worked - this is basically a straight pull from the nginx site for standard WP setups): 下面的配置-希望大家都能看到我所缺少的东西(我已经删除了所有缓存配置,因为它们都不起作用-对于标准的WP设置,这基本上是从nginx站点直接获得的):

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;
}

}

What needs to be added to that to set up nginx's cache? 要设置nginx的缓存,需要添加什么内容?

Change 更改

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}

To

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM