nginx&Wordpressで404のキャッシュが生成されません。
user -> nginx -> apache(Wordpress)
という構成になっています。
200のキャッシュは生成されて問題ないのですが、404のキャッシュは生成されず、常にbackendのapacheをアクセスするようになってしまいます。
なぜ404キャッシュが生成されないのでしょうか?
設定は以下のようになっています。
/etc/nginx/nginx.conf
user nginx nginx;
worker_processes 2;
worker_rlimit_nofile 10240;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 8192;
use epoll;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
server_name_in_redirect off;
server_tokens off;
sendfile on;
tcp_nopush off;
keepalive_timeout 5;
client_max_body_size 4M;
client_body_buffer_size 256k;
if_modified_since before;
gzip on;
gzip_http_version 1.0;
gzip_vary on;
gzip_comp_level 6;
gzip_types text/plain
text/xml
text/css
text/javascript
application/xhtml+xml
application/xml
application/rss+xml
application/atom_xml
application/javascript
application/x-javascript
application/x-httpd-php;
gzip_disable "MSIE [1-6]\.";
# proxy cache
proxy_cache_path /var/cache/nginx/proxy_cache levels=1:2
keys_zone=czone:32m max_size=256m inactive=1440m;
proxy_temp_path /var/cache/nginx/proxy_temp;
proxy_cache_key "$scheme://$host$request_uri";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Remote-Addr $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-UA-Detect $mobile;
proxy_set_header Accept-Encoding "";
proxy_hide_header X-Pingback;
proxy_hide_header Link;
proxy_hide_header ETag;
proxy_connect_timeout 5;
proxy_send_timeout 10;
proxy_read_timeout 90;
proxy_cache_use_stale timeout invalid_header http_500 http_502 http_503 http_504;
proxy_cache_lock on;
proxy_cache_lock_timeout 5s;
proxy_buffers 8 32k;
proxy_buffer_size 64k;
include /etc/nginx/conf.d/*.conf;
}
/etc/nginx/conf.d/default.conf
limit_req_zone $binary_remote_addr zone=one:10m rate=50r/s;
limit_req_log_level info;
upstream backend {
server xxx.xxx.xxx.xxx:8080;
}
server {
listen 80 default;
server_name example.com;
index index.html index.htm;
charset utf-8;
access_log /var/log/nginx/example.com.access.log main;
error_log /var/log/nginx/example.com.error.log;
set $mobile '';
include /etc/nginx/mobile-detect;
set $do_not_cache 0;
if ($http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {
set $do_not_cache 1;
}
if ($request_method != GET) {
set $do_not_cache 1;
}
location / {
limit_req zone=one;
proxy_no_cache $do_not_cache;
proxy_cache_bypass $do_not_cache;
proxy_redirect off;
proxy_cache czone;
proxy_cache_key "$scheme://$host$request_uri$mobile";
proxy_cache_valid 200 6h;
proxy_cache_valid 404 20m;
proxy_pass http://backend;
}
error_page 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}