Welcome! Log In Create A New Profile

Advanced

How to Nginx cache server setting

February 27, 2014 10:50AM
Hi everyone

I would like to make reverse proxy and cache server from Nginx using CentOS6.5,
The setup of Nginx is as follows.

But, cache information is not saved in /var/cache/nginx/hoge.com of proxy_cache_path.
Is this because a setup is wrong?

Please advise me.

Regards
TETSUYA Saito

【/etc/nginx/nginx.conf】
user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


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" "$gzip_ratio"';

access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush off;

keepalive_timeout 65;

gzip on;
gzip_http_version 1.0;
gzip_types text/plain
text/xml
text/css
application/xml
application/xhtml+xml
application/rss+xml
application/atom_xml
application/javascript
application/x-javascript
application/x-httpd-php;
gzip_disable "MSIE [1-6]\.";
gzip_disable "Mozilla/4";
gzip_comp_level 2;
gzip_vary on;
gzip_proxied any;
gzip_buffers 4 8k;

server_names_hash_bucket_size 128; # 32/64/128

include /etc/nginx/conf.d/*.conf;
}

【/etc/nginx/conf.d/proxy.conf】
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $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;
add_header X-Cache $upstream_cache_status;

proxy_connect_timeout 60;
proxy_read_timeout 90;
proxy_send_timeout 60;

proxy_buffering on;
proxy_buffer_size 8k;
proxy_buffers 100 8k;

【/etc/nginx/conf.d/virtual.conf】
upstream backend {
ip_hash;
server hoge:80;
}

proxy_cache_path /var/cache/nginx/hoge.com levels=1:2 keys_zone=cache_hoge.com:15m inactive=7d max_size=512m;
proxy_temp_path /var/cache/nginx/temp 1 2;

server {
listen 80;
server_name www.hoge.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
access_log /var/log/nginx/wp01.night-walker.asia/access_log main;
error_log /var/log/nginx/wp01.night-walker.asia/error_log;

if ($http_host = night-walker.asia) {
rewrite (.*) http://wp01.night-walker.asia;
}

try_files $uri $uri/ /index.php?q=$uri&$args;

location / {
set $do_not_cache 0;

# -- POST or HEAD ?
if ($request_method != "GET") {
set $do_not_cache 1;
}

# -- Login or Comment or Post Editting ?
if ($http_cookie ~ ^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$) {
set $do_not_cache 1;
}

# -- mobile ?
if ($http_x_wap_profile ~ ^[a-z0-9\"]+) {
set $do_not_cache 1;
}

# -- Mobile ?
if ($http_profile ~ ^[a-z0-9\"]+) {
set $do_not_cache 1;
}

# -- Kei-tai ?
if ($http_user_agent ~ ^.*(2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800).*) {
set $do_not_cache 1;
}

# -- Mobile ?
if ($http_user_agent ~ ^(w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-).*) {
set $do_not_cache 1;
}

# -- Kei-tai ?
if ($http_user_agent ~ ^(DoCoMo/|J-PHONE/|J-EMULATOR/|Vodafone/|MOT(EMULATOR)?-|SoftBank/|[VS]emulator/|KDDI-|UP\.Browser/|emobile/|Huawei/|IAC/|Nokia|mixi-mobile-converter/)) {
set $do_not_cache 1;
}

# -- Kei-tai ?
if ($http_user_agent ~ (DDIPOCKET\;|WILLCOM\;|Opera\ Mini|Opera\ Mobi|PalmOS|Windows\ CE\;|PDA\;\ SL-|PlayStation\ Portable\;|SONY/COM|Nitro|Nintendo)) {
set $do_not_cache 1;
}

proxy_cache cache_hoge.com;
proxy_cache_valid 200 2h;
proxy_cache_valid 302 2h;
proxy_cache_valid 301 4h;
proxy_cache_valid any 1m;
proxy_no_cache $do_not_cache;
proxy_cache_bypass $do_not_cache;
resolver 127.0.0.1;
proxy_pass http://$host;
proxy_cache_key $scheme://$host$request_uri;
}
}


_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

How to Nginx cache server setting

tetuya0703 February 27, 2014 10:50AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 309
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready