簡體   English   中英

需要Nginx“ Proxy_Cache”配置幫助

[英]Nginx “Proxy_Cache” Configuration Help Needed

我遇到了一個很奇怪的問題。 我只想為“ new-site.com”啟用代理緩存。 但是,這樣做時,Nginx是代理緩存我所有的網站。

我檢查了所有的vhost / config文件,並確保正確打開和關閉所有“ http”和“ server”塊。 據我了解,僅當您包含(例如)“ proxy_cache new-site;”時,才為站點啟用Proxy_Cache; 在您的網站“服務器”塊中。

在我的“ http”塊中,我加載了所有網站.conf文件,但是它們都不包含任何proxy_cache指令。

我究竟做錯了什么?

這是我的配置文件的片段:

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” vhost conf文件:

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)$ {
         ....
     }
}

一旦我移動了行“ proxy_cache new-site;” 進入“位置”區塊,為我解決了該問題。

不知道為什么當我坐在一個街區之外時會有這個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM