{"id":1539,"date":"2023-12-05T11:39:08","date_gmt":"2023-12-05T03:39:08","guid":{"rendered":"https:\/\/www.yeetrack.com\/?p=1539"},"modified":"2023-12-05T11:39:08","modified_gmt":"2023-12-05T03:39:08","slug":"wordpress%e4%bd%bf%e7%94%a8nginx%e5%a2%9e%e5%8a%a0%e9%a1%b5%e9%9d%a2%e7%bc%93%e5%ad%98%ef%bc%8c%e5%87%8f%e5%b0%91%e6%9c%8d%e5%8a%a1%e7%ab%af%e8%b5%84%e6%ba%90%e6%b6%88%e8%80%97","status":"publish","type":"post","link":"https:\/\/www.yeetrack.com\/?p=1539","title":{"rendered":"wordpress\u4f7f\u7528nginx\u589e\u52a0\u9875\u9762\u7f13\u5b58\uff0c\u51cf\u5c11\u670d\u52a1\u7aef\u8d44\u6e90\u6d88\u8017"},"content":{"rendered":"<p>WordPress\u6709\u591a\u4e2a\u7ea7\u522b\u7684\u7f13\u5b58\u53ef\u4ee5\u914d\u7f6e\uff0c\u5982\u4f7f\u7528Redis\u7f13\u5b58\u51cf\u5c11mysql\u6570\u636e\u5e93\u7684\u538b\u529b\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528nginx\u9759\u6001\u7f13\u5b58\u51cf\u5c11php\u53camysql\u7684\u538b\u529b\uff0c\u4e00\u822c\u4e0d\u4f1a\u6d89\u53ca\u5230nginx\u7cfb\u7edf\u914d\u7f6e\u6587\u4ef6<code>nginx.conf<\/code>\uff0c\u53ea\u4fee\u6539\u81ea\u5df1\u7684\u7f51\u7ad9\u914d\u7f6e\u6587\u4ef6\u5373\u53ef\uff0c\u5982<code>xxx.com.conf<\/code>\u3002  <\/p>\n<p><!--more--><\/p>\n<pre><code>    fastcgi_cache_path  \/your\/path levels=1:2 keys_zone=your_keyword:128m inactive=1d max_size=10g;\n    fastcgi_temp_path \/your\/path2;\n    fastcgi_cache_key \"$scheme$request_method$host$request_uri\";\n    fastcgi_cache_use_stale error timeout invalid_header http_500;\n\n    fastcgi_ignore_headers Cache-Control Expires Set-Cookie;\n\n    server{\n    ...\n        set $skip_cache 0;\n        #post\u8bbf\u95ee\u4e0d\u7f13\u5b58\n        if ($request_method = POST) {\n            set $skip_cache 1;\n        }\n        #\u52a8\u6001\u67e5\u8be2\u4e0d\u7f13\u5b58\n        if ($query_string != \"\") {\n            set $skip_cache 1;\n        }\n        #\u5177\u4f53\u7684\u6587\u7ae0\u9875\u9762\uff0c\u7f13\u5b58\n        #\u540e\u53f0\u7b49\u7279\u5b9a\u9875\u9762\u4e0d\u7f13\u5b58\uff08\u5176\u4ed6\u9700\u6c42\u8bf7\u81ea\u884c\u6dfb\u52a0\u5373\u53ef\uff09\n        if ($request_uri ~* \"\/wp-admin\/|wp-.*.php|\/feed\/|index.php|sitemap(_index)?.xml\") {\n            set $skip_cache 1;\n        }\n        #\u5bf9\u767b\u5f55\u7528\u6237\u3001\u8bc4\u8bba\u8fc7\u7684\u7528\u6237\u4e0d\u5c55\u793a\u7f13\u5b58\n        if ($http_cookie ~* \"comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in\") {\n            set $skip_cache 1;\n        }\n\n        ...\n        location ~* ^.+\\.(ogg|ogv|svg|svgz|eot|otf|woff|woff2|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {\n            expires 100d;\n        }\n\n        location ~ \\.php$ {\n            fastcgi_pass   unix:\/somedir\/php\/php8.1-fpm.sock;\n            fastcgi_index  index.php;\n            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;\n            include        fastcgi_params;\n            add_header Strict-Transport-Security \"max-age=63072000; includeSubdomains; preload\";\n            #\u65b0\u589e\u7684\u7f13\u5b58\u89c4\u5219\n            fastcgi_cache_bypass $skip_cache;\n            fastcgi_no_cache $skip_cache;\n            add_header Last-Modified $date_gmt;\n            add_header X-Frame-Options SAMEORIGIN;\n            add_header X-Content-Type-Options nosniff;\n            add_header X-XSS-Protection \"1; mode=block\";\n            fastcgi_cache some_keyword;\n            fastcgi_cache_valid 200 301 302 1d;\n            proxy_cache_valid 404 30m;\n            proxy_cache_valid any 1h;\n        }\n    }<\/code><\/pre>\n<p>nginx\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6\u751f\u6548\uff0c<code>nginx -s reload<\/code>\u3002\u8bbf\u95ee\u524d\u7aef\u9875\u9762\u540e\uff0c\u4e5f\u5df2\u5728\u6307\u5b9a\u7684\u7f13\u5b58\u8def\u5f84\u4e0b\uff0c\u770b\u5230\u5f88\u591anginx\u81ea\u5df1\u751f\u6210\u7684\u7f13\u5b58\u6587\u4ef6\u3002\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\uff0c\u8c03\u6574\u7f13\u5b58\u4e0a\u9762\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u7f13\u5b58\u7b56\u7565\uff0c\u65f6\u95f4\u7b49\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress\u6709\u591a\u4e2a\u7ea7\u522b\u7684\u7f13\u5b58\u53ef\u4ee5\u914d\u7f6e\uff0c\u5982\u4f7f\u7528Redis\u7f13\u5b58\u51cf\u5c11mysql\u6570\u636e\u5e93\u7684\u538b\u529b\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528nginx\u9759\u6001\u7f13\u5b58\u51cf\u5c11php\u53camysql\u7684\u538b\u529b\uff0c\u4e00\u822c\u4e0d\u4f1a\u6d89\u53ca\u5230nginx\u7cfb\u7edf\u914d\u7f6e\u6587\u4ef6nginx.c&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[34],"tags":[58,25],"class_list":["post-1539","post","type-post","status-publish","format-standard","hentry","category-software","tag-nginx","tag-wordpress"],"views":1079,"_links":{"self":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/1539","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1539"}],"version-history":[{"count":1,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/1539\/revisions"}],"predecessor-version":[{"id":1540,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/1539\/revisions\/1540"}],"wp:attachment":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1539"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1539"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}