{"id":1653,"date":"2023-03-25T21:53:44","date_gmt":"2023-03-25T13:53:44","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1653"},"modified":"2023-04-23T21:56:43","modified_gmt":"2023-04-23T13:56:43","slug":"magento-access-varnish","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/25\/magento-access-varnish\/","title":{"rendered":"Magento\u63a5\u5165Varnish"},"content":{"rendered":"<blockquote>\n<p>Varnish\u662f\u4e00\u6b3e\u9ad8\u6027\u80fd\u7684\u5f00\u6e90HTTP\u52a0\u901f\u5668\uff0c\u53ef\u4ee5\u6709\u6548\u964d\u4f4eweb\u670d\u52a1\u5668\u7684\u8d1f\u8f7d\uff0c\u63d0\u5347\u8bbf\u95ee\u901f\u5ea6\u3002\u6839\u636e\u5b98\u65b9\u7684\u8bf4\u6cd5\uff0cVarnish\u662f\u4e00\u4e2acache\u578b\u7684HTTP\u53cd\u5411\u4ee3\u7406\u3002<\/p>\n<\/blockquote>\n<p>\u57fa\u4e8eM2.3.5\u548cVarnish4.x<\/p>\n<h3>\u5b89\u88c5Varnish<\/h3>\n<p><!-- more --><\/p>\n<pre><code class=\"language-bash\">wget http:\/\/dl.fedoraproject.org\/pub\/epel\/epel-release-latest-7.noarch.rpm\nrpm -ivh epel-release-latest-7.noarch.rpm\nyum update &amp;&amp; yum install varnish<\/code><\/pre>\n<p>\u914d\u7f6eVarnish<\/p>\n<pre><code class=\"language-bash\">vim \/etc\/varnish\/varnish.params\n\nVARNISH_LISTEN_PORT=6081\nVARNISH_ADMIN_LISTEN_PORT=6082\nDAEMON_OPTS=&quot;-a :6081\n-T localhost:6082\n-f \/etc\/varnish\/default.vcl\n-S \/etc\/varnish\/secret\n-p thread_pool_min=5\n-p thread_pool_max=500 \\\n-p http_resp_hdr_len=65536\n-p http_resp_size=98304\n-p workspace_backend=98304 \\\n-s malloc,256m&quot;<\/code><\/pre>\n<pre><code class=\"language-bash\">cp \/etc\/varnish\/default.vcl \/etc\/varnish\/default.vcl.bak<\/code><\/pre>\n<h3>M2\u914d\u7f6e<\/h3>\n<p><code>Stores<\/code> &#8211; <code>Configuration<\/code> &#8211; <code>Advanced<\/code> &#8211; <code>System<\/code> &#8211; <code>Full Page Cache<\/code><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/PHP\/Magento-Varnish.png\" alt=\"Magento Varnish\u914d\u7f6e\" \/><\/p>\n<p>\u7136\u540e\u5c06\u540e\u53f0\u5bfc\u51fa<code>default.vcl<\/code>\u4e0a\u4f20\u5230\u670d\u52a1\u5668\uff0c\u5982\u679c\u4f7f\u7528<code>Nginx<\/code>\uff0c\u8fd8\u9700\u8981\u5c06<code>\/pub\/health_check.php<\/code>\u6539\u4e3a<code>\/health_check.php<\/code>\u3002<\/p>\n<h3>\u542f\u52a8Varnish<\/h3>\n<pre><code class=\"language-bash\">systemctl start varnish<\/code><\/pre>\n<h3>Nginx\u914d\u7f6e<\/h3>\n<pre><code class=\"language-json\">map $request_uri $MAGE_RUN_CODE {\n    default base;\n}\n\nmap $request_uri $MAGE_RUN_TYPE {\n    default website;\n}\n\nserver {\n    listen 80;\n    server_name test.magento.com;\n\n    location \/ { \n        proxy_pass http:\/\/127.0.0.1:6081; \n        proxy_set_header Host $http_host; \n        proxy_set_header X-Forwarded-Host $http_host;\n        proxy_set_header X-Real-IP $remote_addr; \n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; \n    }\n}\n\nserver {\n    listen 443 ssl http2 default_server;\n    listen [::]:443 ssl http2 default_server;\n    server_name test.magento.com;\n\n    #ssl on;\n    ssl_certificate \/usr\/local\/nginx\/client_body_temp\/2547820_test.magento.com.pem;\n    ssl_certificate_key \/usr\/local\/nginx\/client_body_temp\/2547820_test.magento.com.key;\n    ssl_session_cache shared:SSL:1m;\n    ssl_session_timeout 10m;\n    ssl_ciphers HIGH:!aNULL:!MD5;\n    ssl_prefer_server_ciphers on;\n\n    location \/ { \n        proxy_pass http:\/\/127.0.0.1:6081; \n        proxy_set_header Host $http_host; \n        proxy_set_header X-Forwarded-Host $http_host;\n        proxy_set_header X-Real-IP $remote_addr; \n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; \n        proxy_set_header X-Forwarded-Proto https; \n        proxy_set_header X-Forwarded-Port 443; \n    } \n}\n\nserver {\n    listen 8080;\n    server_name test.magento.com;           \n\n    set $MAGE_ROOT \/var\/www\/html\/magento;\n    include \/var\/www\/html\/magento\/nginx.conf.sample;\n}<\/code><\/pre>\n<p>\u7528\u6237\u901a\u8fc7http\uff0880\u7aef\u53e3\uff09\u6216\u8005https\uff08443\u7aef\u53e3\uff09\u8bbf\u95ee\u65f6\uff0c\u4f7f\u7528Nginx\u7684<code>proxy_pass<\/code>\u547d\u4ee4\uff0c\u53cd\u5411\u4ee3\u7406\u5230<code>6081<\/code>\u7aef\u53e3\uff0c\u7531Varnish\u8fd4\u56de\u6570\u636e\u3002<\/p>\n<h3>\u7ed1\u5b9avarnish\u4e3b\u673a<\/h3>\n<pre><code class=\"language-bash\">bin\/magento setup:config:set --http-cache-hosts=127.0.0.1:6081<\/code><\/pre>\n<p>\u8fd9\u6837\uff0c\u4f7f\u7528<code>cache:clean<\/code>\u5c31\u80fd\u540c\u65f6\u628aVarnish\u7684\u7f13\u5b58\u6e05\u7406\u6389\u4e86\u3002<\/p>\n<h3>\u6b63\u5411\u4ee3\u7406\u548c\u53cd\u5411\u4ee3\u7406<\/h3>\n<p>\u9898\u5916\u8bdd\uff0c\u65e0\u8bba\u6b63\u5411\u4ee3\u7406\u8fd8\u662f\u53cd\u5411\u4ee3\u7406\uff0c\u5176\u5b9e\u90fd\u662f\u4f7f\u7528proxy_pass\u547d\u4ee4\u5b9e\u73b0\u3002\u6b63\u5411\u8fd8\u662f\u53cd\u5411\uff0c\u53ef\u4ee5\u770b\u4ee3\u7406\u7684\u5bf9\u8c61\u662f\u5ba2\u6237\u7aef\u8fd8\u662f\u670d\u52a1\u7aef\u3002<\/p>\n<ul>\n<li>\u6b63\u5411\uff1a\u4ee3\u7406\u5ba2\u6237\u7aef\uff0c\u670d\u52a1\u7aef\u65e0\u6cd5\u77e5\u9053\u5b9e\u9645\u8bf7\u6c42\u7684\u5ba2\u6237\u7aef<\/li>\n<li>\u53cd\u5411\uff1a\u4ee3\u7406\u670d\u52a1\u7aef\uff0c\u5ba2\u6237\u7aef\u65e0\u6cd5\u77e5\u9053\u5b9e\u9645\u54cd\u5e94\u7684\u670d\u52a1\u7aef\u3002\u5982\uff1aCDN\uff0c\u8d1f\u8f7d\u5747\u8861\uff0cvarnish\u7f13\u5b58<\/li>\n<\/ul>\n<p>\u8865\u5145\u4e00\u5f20\u6bd4\u8f83\u76f4\u89c2\u7684\u56fe\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/PHP\/Varnish\u5de5\u4f5c\u539f\u7406.png\" alt=\"Magento Varnish\u5de5\u4f5c\u539f\u7406\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Varnish\u662f\u4e00\u6b3e\u9ad8\u6027\u80fd\u7684\u5f00\u6e90HTTP\u52a0\u901f\u5668\uff0c\u53ef\u4ee5\u6709\u6548\u964d\u4f4eweb\u670d\u52a1\u5668\u7684\u8d1f\u8f7d\uff0c\u63d0\u5347\u8bbf\u95ee\u901f\u5ea6\u3002\u6839\u636e\u5b98\u65b9\u7684\u8bf4\u6cd5\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[78],"tags":[],"class_list":["post-1653","post","type-post","status-publish","format-standard","hentry","category-magento"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1653","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1653"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1653\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}