VPS侦探论坛

 找回密码
 注册
查看: 6936|回复: 3

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

[复制链接]
发表于 2011-8-28 20:03:38 | 显示全部楼层 |阅读模式

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

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

nginx.conf  改了部分Gzip配置,其他未动
user  www www;
worker_processes 4;
worker_cpu_affinity 0001 0010 0100 1000;
error_log  /home/wwwlogs/nginx_error.log  crit;
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_type  application/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 [1-6].";
  gzip_types text/plain application/x-javascript text/css text/javascript;
  gzip_min_length 1000;
  gzip_buffers 8 16k;
  gzip_comp_level 3;
  #limit_zone  crawler  $binary_remote_addr  10m;
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_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';
  access_log  off;
}
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 编辑 ]
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2011-8-28 22:50:07 | 显示全部楼层


洗把澡,我擦终于想通了

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

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

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

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


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



不知道说的对不对,老大有空帮忙判断下
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2011-8-29 01:38:49 | 显示全部楼层

看了最后一句话我真的是乐喷了啊。。。。都说了NGINX是有代理的功能的,可以使你请求的URL静态化,网页里面一张图片, 一串代码都是有一URL的么,我已经发过贴子了如何去配置静态的URL,自己看看以前的贴么。。。
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2011-8-29 01:40:43 | 显示全部楼层



location @apache {
   internal;
   proxy_pass http://127.0.0.1:88;
   include proxy.conf;
   }
删掉这一些。
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-21 04:35 , Processed in 0.026086 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表