LoginSignup
8

More than 5 years have passed since last update.

AWS + Nginx + WordPressのAMIMOTO開発時キャッシュが消えない時の対処法

Posted at

AMIMOTOを利用していて、キャッシュがなかなか消えなくて苦労していたので、まとめてみた。

基本

キャッシュ削除

$ sudo rm -rf /var/cache/nginx

キャッシュフォルダごと削除

nginxフォルダを作成してあげる

$ mkdir  /var/cache/nginx

nginx構文が正しいかを確認

nginx -t

下記のように出ればOK!

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

nginxの再起動

$ sudo /etc/init.d/nginx restart

本当は上記方法はあまり利用しない方が良いらしい・・・

$ sudo /etc/init.d/nginx stop
$ sudo /etc/init.d/nginx start

それでもダメな場合

nginxの設定を見直す

$ vi /etc/nginx/nginx.conf

inactiveが1000hとかになってると、
キャッシュが1000時間、つまり約16日間もの間キャッシュが残り続ける形となる。
1mとか5mとかの分単位にしてあげると開発環境としては楽。

nginx.conf
# proxy cache
proxy_cache_path  /var/cache/nginx/proxy_cache levels=1:2
                  keys_zone=czone:32m max_size=256m inactive=1m;

エラーが出る場合

nginx -tで下記エラーが出る場合がある。

Starting nginx: nginx: [warn] 2048 worker_connections exceed open file resource limit: 1024

利用可能なメモリー量やCPU時間などが足りない場合上記エラーが出る。
その為、足りなくなっている容量を確認し割り当てる必要がある。

$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 4469
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 4469
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

上記でエラーとなっている項目を確認し容量を増やしてやる。

$ ulimit -u 2048

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
8