【问题标题】:Nginx "Proxy_Cache" Configuration Help Needed需要 Nginx“Proxy_Cache”配置帮助
【发布时间】:2014-06-28 00:21:41
【问题描述】:

我遇到了一个非常奇怪的问题。我只想为“new-site.com”启用代理缓存。但是,这样做时,Nginx 会代理缓存我所有的网站。

我检查了我所有的虚拟主机/配置文件,并确保所有“http”和“server”块都正确打开和关闭。据我了解,仅当您包含(例如)“proxy_cache new-site;”时,才为站点启用 Proxy_Cache。在您的网站“服务器”块中。

在我的“http”块中,我加载了所有网站的 .conf 文件,但它们都不包含任何 proxy_cache 指令。

我做错了什么?

这是我的配置文件的 sn-p :

http {
     ...
     ...

     # nginx cache
     proxy_cache_path  /www/new-site.com/httpdocs/cache levels=1:2
                       keys_zone=new-site:10m
                       max_size=50m
                       inactive=1440m;
     proxy_temp_path   /www/new-site.com/httpdocs/cache/tmp 1 2;    

     # virtual hosting
     include /etc/nginx/vhosts/*.conf;
}

然后这是我的“new-site.com”虚拟主机配置文件:

server {

     listen          xxx.xxx.xxx.xxx:80;

     server_name     new-site.com;

     root            /www/new-site.com/httpdocs;
     index           index.php;

     ...
     ...

     proxy_cache  new-site;

     location / {
         try_files $uri @backend;
     }

    location ~* \.php {

         include /usr/local/etc/nginx/proxypass.conf;

         proxy_ignore_headers  Expires Cache-Control;
         proxy_cache_use_stale  error timeout invalid_header updating http_502;
         proxy_cache_bypass  $cookie_session $http_secret_header;
         proxy_no_cache  $cookie_session;
         add_header X-Cache  $upstream_cache_status;
         proxy_cache_valid 200 302 5m;
         proxy_cache_valid 404 1m;
         proxy_pass  http://127.0.0.1:80;
     }

     location @backend {
         include /usr/local/etc/nginx/proxypass.conf;

         proxy_ignore_headers  Expires Cache-Control;
         proxy_cache_use_stale  error timeout invalid_header updating http_502;
         proxy_cache_bypass  $cookie_session $http_secret_header;
         proxy_no_cache  $cookie_session;
         add_header X-Cache  $upstream_cache_status;
         proxy_cache_valid 200 302 5m;
         proxy_cache_valid 404 1m;
         proxy_pass  http://127.0.0.1:80;
     }

     location ~* \.(jpg|jpeg|gif|png|bmp|ico|pdf|flv|swf|css|js)$ {
         ....
     }
}

【问题讨论】:

    标签: nginx


    【解决方案1】:

    一旦我移动了“proxy_cache new-site;”行进入“位置”块,为我解决了这个问题。

    不知道为什么当它位于街区外时我会遇到这个问题。

    【讨论】:

      猜你喜欢
      • 2017-03-20
      • 1970-01-01
      • 1970-01-01
      • 2011-07-23
      • 1970-01-01
      • 2020-07-09
      • 2021-10-18
      • 1970-01-01
      • 2020-10-19
      相关资源
      最近更新 更多