Nginx кэширование

VM
На сайте с 23.09.2009
Offline
192
1527

Пытаюсь разобраться как это все работает.. Гляньте пожалуйста конфиг, где что поправить, на сервере 2 сайта. Один на DLE, второй на WP

http {

proxy_cache_path /var/cache/nginx/proxy_cache levels=1:2 keys_zone=hrportal:10m inactive=7d max_size=1024m;

server {

server_name test.ru www.test.ru;

listen 127.0.0.1;

charset WINDOWS-1251;

disable_symlinks if_not_owner from=$root_path;

set $root_path /var/www/vhvvx777/data/www/test.ru;

location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|pdf|ppt|txt|svg|bmp|rtf|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf|torrent)$ {

root $root_path;

access_log /var/www/nginx-logs/vhvvx777 isp;

access_log /var/www/httpd-logs/test.ru.access.log ;

error_page 404 = @fallback;

expires max;

add_header Last-Modified $sent_http_Expires;

}

location @nocached {

proxy_pass http://127.0.0.1:81;

proxy_redirect http://127.0.0.1:81/ /;

proxy_set_header Host $host;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Real-IP $remote_addr;

}

location / {

proxy_pass http://127.0.0.1:81;

proxy_redirect http://127.0.0.1:81/ /;

proxy_set_header Host $host;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Forwarded-Proto $scheme;

proxy_set_header X-Real-IP $remote_addr;

#здесь мы фильтруем наших залогиненых пользователей

if ($cookie_dle_user_id) { return 412; }

if ($cookie_dle_password) { return 412; }

if ($request_method = POST ) {

return 412;

}

error_page 412 = @nocached;

proxy_cache hrportal;

proxy_cache_key "$request_method|$is_args|$host|$request_uri";

proxy_no_cache $cookie_logged;

proxy_cache_bypass $cookie_logged;

proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;

proxy_pass_header Set-Cookie;

proxy_ignore_headers "Expires" "Cache-Control";

proxy_cache_valid 404 502 503 1m;

proxy_cache_valid any 1h;

limit_req zone=one burst=4;

}

location ~ (admin.php|index.php?action=logout) {

proxy_pass http://127.0.0.1:81;

proxy_redirect http://127.0.0.1:81/ /;

proxy_set_header Host $host;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Real-IP $remote_addr;

}

location ~* ^/(webstat|awstats|webmail|myadmin|pgadmin)/ {

proxy_pass http://127.0.0.1:81;

proxy_redirect http://127.0.0.1:81/ /;

proxy_set_header Host $host;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Forwarded-Proto $scheme;

proxy_set_header X-Real-IP $remote_addr;

}

location @fallback {

proxy_pass http://127.0.0.1:81;

proxy_set_header Host $host;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Forwarded-Proto $scheme;

proxy_set_header X-Real-IP $remote_addr;

}

location ^~ /webstat/ {

auth_basic "Restricted area";

auth_basic_user_file /var/www/vhvvx777/data/etc/528887.passwd;

try_files $uri @fallback;

}

include /usr/local/ispmgr/etc/nginx.inc;

}

server {

server_name test.com www.test.com;

listen 127.0.0.1;

charset UTF-8;

disable_symlinks if_not_owner from=$root_path;

set $root_path /var/www/undershot/data/www/test.com;

location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|pdf|ppt|txt|svg|bmp|rtf|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf|torrent)$ {

root $root_path;

access_log /var/www/nginx-logs/undershot isp;

access_log /var/www/httpd-logs/test.com.access.log ;

error_page 404 = @fallback;

expires max;

add_header Last-Modified $sent_http_Expires;

}

location = /favicon.ico {

log_not_found off;

access_log off;

}

location = /robots.txt {

allow all;

log_not_found off;

access_log off;

}

location / {

proxy_pass http://127.0.0.1:81

proxy_redirect http://127.0.0.1:81/ /;

proxy_set_header Host $host;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Forwarded-Proto $scheme;

proxy_set_header X-Real-IP $remote_addr;

set $cache_uri $request_uri;

# Запретить кэширование, если используются POST запросы.

if ($request_method = POST) {

set $cache_uri 'null cache';

}

if ($query_string != "") {

set $cache_uri 'null cache';

}

# Запретить кэширование при доступе к служебным скриптам.

if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {

set $cache_uri 'null cache';

}

# Запретить кэширование, если используются cookie.

if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {

set $cache_uri 'null cache';

}

proxy_cache hrportal;

proxy_cache_key $host$uri?$args;

proxy_no_cache $cookie_logged;

proxy_cache_bypass $cookie_logged;

proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;

proxy_pass_header Set-Cookie;

proxy_ignore_headers "Expires" "Cache-Control";

proxy_cache_valid 404 502 503 1m;

proxy_cache_valid any 1h;

limit_req zone=one burst=4;

}

location ~* ^/(webstat|awstats|webmail|myadmin|pgadmin)/ {

proxy_pass http://127.0.0.1:81

proxy_redirect http://127.0.0.1:81/ /;

proxy_set_header Host $host;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Forwarded-Proto $scheme;

proxy_set_header X-Real-IP $remote_addr;

}

location @fallback {

proxy_pass http://127.0.0.1:81

proxy_set_header Host $host;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Forwarded-Proto $scheme;

proxy_set_header X-Real-IP $remote_addr;

}

location ^~ /webstat/ {

auth_basic "Restricted area";

auth_basic_user_file /var/www/undershot/data/etc/786132.passwd;

try_files $uri @fallback;

}

include /usr/local/ispmgr/etc/nginx.inc;

}

}

[Удален]
#1

Ну для начала в listen 127.0.0.1; не мешало бы прописать реальный IP.

VM
На сайте с 23.09.2009
Offline
192
#2
WapGraf:
Ну для начала в listen 127.0.0.1; не мешало бы прописать реальный IP.

айпи прописан реальный, в посте заменил чтобы не палить ☝

---------- Добавлено 12.11.2015 в 18:13 ----------

вообще суть проблемы в том что кэшируются не нужные мне папки в WP

Мне нужно отключить кэширование в этих директориях

wp-admin

/moon

/h

unreturned
На сайте с 20.03.2013
Offline
57
#3

Попробуйте ознакомиться со статьей https://www.nginx.com/blog/9-tips-for-improving-wordpress-performance-with-nginx/

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий