login.zhang 发表于 2011-8-28 20:03:38

老大帮我看下Nginx缓存哪里配错了,谢谢!

坛子里已搜,Google百度均为解决,老大帮忙看下...

涉及的目录都是755权限,用户是www.root , 缓存文件夹是nginx自动生成的,我就改了权限755

nginx.conf改了部分Gzip配置,其他未动
userwww www;
worker_processes 4;
worker_cpu_affinity 0001 0010 0100 1000;
error_log/home/wwwlogs/nginx_error.logcrit;
pid      /usr/local/nginx/logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{
include       mime.types;
default_typeapplication/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush   on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
gzip on;
gzip_http_version 1.1;
gzip_disable "MSIE .";
gzip_types text/plain application/x-javascript text/css text/javascript;
gzip_min_length 1000;
gzip_buffers 8 16k;
gzip_comp_level 3;
#limit_zonecrawler$binary_remote_addr10m;
server
{
listen       80;
server_name srv.itpower.info;
index index.html index.htm index.php;
root/home/srv.itpower.info;
location / {
   try_files $uri @apache;
   }
location @apache {
   internal;
   proxy_pass http://127.0.0.1:88;
   include proxy.conf;
   }
location ~ .*\.(php|php5)?$
   {
    proxy_pass http://127.0.0.1:88;
    include proxy.conf;
   }
location /status {
   stub_status on;
   access_log   off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
   {
    expires      30d;
   }
location ~ .*\.(js|css)?$
   {
    expires      12h;
   }
log_formataccess'$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';
access_logoff;
}
include vhost/*.conf;
}


www.itpower.info.conf 部分
proxy_cache_path /home/wwwcache levels=1:2 keys_zone=CACHE:1000M inactive=30d max_size=2M;
proxy_temp_path /home/wwwtemp;
server
{
listen       80;
server_name www.itpower.info itpower.info;
index index.html index.htm index.php default.html default.htm default.php;
root/home/www.itpower.info;
location / {
   root /home/wwwtemp;
   try_files $uri @apache;
   }
location @apache {
   internal;
   proxy_pass http://127.0.0.1:88;
   include proxy.conf;
   }
location ~ .*\.(php|php5)?$
   {
    proxy_pass http://127.0.0.1:88;
    include proxy.conf;
   }
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
   {
    expires      30d;
    proxy_cache CACHE;
    proxy_cache_valid 200 30d;
    proxy_cache_valid any 1m;
    proxy_ignore_headers "Cache-Control" "Expires";
   }
location ~ .*\.(js|css)?$
   {
    expires      30d;
    proxy_cache CACHE;
    proxy_cache_valid 200 30d;
    proxy_cache_valid any 1m;
    proxy_ignore_headers "Cache-Control" "Expires";
   }
access_log off;
}
server
{
listen               443;
ssl                  on;
ssl_certificate      /usr/local/nginx/ssl/itpower.cer;
ssl_certificate_key/usr/local/nginx/ssl/itpower.key;
server_name www.itpower.info itpower.info;
index index.html index.htm index.php default.html default.htm default.php;
root/home/www.itpower.info;
location / {
   try_files $uri @apache;
   }
location @apache {
   internal;
   proxy_pass http://127.0.0.1:88;
   include proxy.conf;
   }
location ~ .*\.(php|php5)?$
   {
    proxy_pass http://127.0.0.1:88;
    include proxy.conf;
   }
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
   {
    expires      30d;
   }
location ~ .*\.(js|css)?$
   {
    expires      12h;
   }
access_log off;
}

[ 本帖最后由 login.zhang 于 2011-8-28 20:07 编辑 ]

login.zhang 发表于 2011-8-28 22:50:07

洗把澡,我擦终于想通了

配置没问题,关键是理解错了

Proxy_Cache是将后端的文件缓存起来,前提是“向后端请求的文件”

LNMPA架构中,静态文件全部是NGINX自己读取并处理,并不是向后端请求来的,所以不存在Proxy,更不存在Cache

而且Apache只load了1个php module以便和NGINX配合


估计最近折腾整体性能优化入魔了,看到什么优化的想都不详直接配,没有仔细思考使用环境



不知道说的对不对,老大有空帮忙判断下

yuweitaocn 发表于 2011-8-29 01:38:49

看了最后一句话我真的是乐喷了啊。。。。都说了NGINX是有代理的功能的,可以使你请求的URL静态化,网页里面一张图片, 一串代码都是有一URL的么,我已经发过贴子了如何去配置静态的URL,自己看看以前的贴么。。。

yuweitaocn 发表于 2011-8-29 01:40:43

location @apache {
   internal;
   proxy_pass http://127.0.0.1:88;
   include proxy.conf;
   }
删掉这一些。
页: [1]
查看完整版本: 老大帮我看下Nginx缓存哪里配错了,谢谢!