gpt4 book ai didi

php - Magento 阻止 Varnish 缓存页面

转载 作者:搜寻专家 更新时间:2023-10-31 21:52:35 24 4
gpt4 key购买 nike

如果将 header 更改为 header('Cache-Control: public, max-age=10');,Varnish 将完美运行。

但 Magento 使用自己的 header 覆盖 header :Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 , s-maxage=86400

导致从不缓存页面。但是您也不希望 Varnish 缓存登录用户...那么我应该如何配置 Varnish 和/或 Magento 来缓存缓存所需的内容?

Varnish 4.0 (4.0.3-1)

PHP 5.6 (5.6.24-1)

Nginx 1.0.15 (1.0.15-12)

Magento 1.9 (1.9.2.4)

这是我的 HTTP header :

HTTP/1.1 200 OK
Server: nginx
Date: Mon, 08 Aug 2016 08:46:28 GMT
Content-Type: text/html; charset=UTF-8
X-Powered-By: PHP/5.6.24
X-Frame-Options: SAMEORIGIN
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, s-maxage=86400
Expires: Mon, 31 Mar 2008 10:00:00 GMT
Pragma: no-cache
Content-Encoding: gzip
Vary: Accept-Encoding
X-Varnish: 32770
Age: 0
Via: 1.1 varnish-v4
Content-Length: 0
Connection: keep-alive

我的 Varnish vcl 配置:

backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
unset req.http.cookie;
}
sub vcl_backend_response {
unset beresp.http.set-cookie;
}
sub vcl_deliver {
unset resp.http.set-cookie;
}

我的“nginx.conf”配置

# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes 4;

error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;

pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
server_tokens off;
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"';

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

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

fastcgi_read_timeout 300;

#gzip on;

# Load config files from the /etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
include /etc/nginx/conf.d/*.conf;

}

我的“default.conf”配置:

server {
listen 127.0.0.1:8080;
server_name <my website, www.example.com>;

#charset koi8-r;

#access_log logs/host.access.log main;

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

location / {
root /var/www/public_html;
index index.php index.html index.htm;
try_files $uri $uri/ @handler;
}

## These locations would be hidden by .htaccess normally
location ^~ /app/ { deny all; }
location ^~ /includes/ { deny all; }
location ^~ /lib/ { deny all; }
location ^~ /media/downloadable/ { deny all; }
location ^~ /pkginfo/ { deny all; }
location ^~ /report/config.xml { deny all; }
location ^~ /var/ { deny all; }

location /var/export/ { ## Allow admins only to view export folder
auth_basic "Restricted"; ## Message shown in login window
auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
autoindex on;
}

location /. { ## Disable .htaccess and other hidden files
return 404;
}

location @handler { ## Magento uses a common front handler
rewrite / /index.php;
}

location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}

# location ~ .php$ { ## Execute PHP scripts
# if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
# root /var/www/public_html;
# expires off; ## Do not cache dynamic content
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
# fastcgi_param MAGE_RUN_TYPE store;
# include fastcgi_params; ## See /etc/nginx/fastcgi_params
# }

location ~ ^(.+\.php)(.*)$ {
root /var/www/public_html;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/public_html/$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
}

error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root /var/www/public_html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}

}

最佳答案

您的页面上可能有一些不可缓存的 block 。在 *.xml 文件中搜索 ... cacheable="false"并考虑使 block 可缓存。

确保通过运行启用缓存也可能有意义

bin/magento cache:status

关于php - Magento 阻止 Varnish 缓存页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38824997/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com