{"id":236,"date":"2015-10-28T10:07:38","date_gmt":"2015-10-28T02:07:38","guid":{"rendered":"http:\/\/www.ji-zhi.net\/?p=236"},"modified":"2015-10-28T10:07:38","modified_gmt":"2015-10-28T02:07:38","slug":"config-sample-of-wordpress-on-nginx","status":"publish","type":"post","link":"https:\/\/www.ji-zhi.net\/?p=236","title":{"rendered":"\u53c2\u7167nginx\u5b98\u65b9\u6837\u672c\u91cd\u65b0\u914d\u7f6eWordPress\u7ad9\u70b9"},"content":{"rendered":"<p>nginx\u5b98\u7f51\u63d0\u4f9b\u4e86\u5e38\u7528blog\/cms\u7b49\u7cfb\u7edf\u7684\u793a\u4f8b\u914d\u7f6e\u6587\u4ef6\u3002Wordpress\u7684\u5728<a href=\"https:\/\/www.nginx.com\/resources\/wiki\/start\/topics\/recipes\/wordpress\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u8fd9\u91cc<\/a>\u3002<\/p>\n<p>\u57fa\u7840\u7684\u662f\u8fd9\u6837\uff1a<\/p>\n<pre class=\"\">server {\n        ## Your website name goes here.\n        server_name domain.tld;\n        ## Your only path reference.\n        root \/var\/www\/wordpress;\n        ## This should be in your http block and if it is, it's not needed here.\n        index index.php;\n\n        location = \/favicon.ico {\n                log_not_found off;\n                access_log off;\n        }\n\n        location = \/robots.txt {\n                allow all;\n                log_not_found off;\n                access_log off;\n        }\n\n        location \/ {\n                # This is cool because no php is touched for static content.\n                # include the \"?$args\" part so non-default permalinks doesn't break when using query string\n                try_files $uri $uri\/ \/index.php?$args;\n        }\n\n        location ~ \\.php$ {\n                #NOTE: You should have \"cgi.fix_pathinfo = 0;\" in php.ini\n                include fastcgi.conf;\n                fastcgi_intercept_errors on;\n                fastcgi_pass php;\n        }\n\n        location ~* \\.(js|css|png|jpg|jpeg|gif|ico)$ {\n                expires max;\n                log_not_found off;\n        }\n}\n<\/pre>\n<p>\u540e\u9762\u8fd8\u6709\u4e00\u4e9b\u591a\u7ad9\u5171\u5b58\u4e4b\u7c7b\u7684\u914d\u7f6e\u3002<\/p>\n<p>\u6309\u7167\u8fd9\u4e2a\u8303\u672c\u6211\u5bf9\u6211\u81ea\u5df1\u7684\u914d\u7f6e\u505a\u4e86\u4e00\u4e9b\u8c03\u6574\uff0c\u8bd5\u4e86\u4e00\u4e0b\u5b8c\u5168\u53ef\u884c\uff0c\u6bd4\u539f\u6765\u7684\u597d\u7528\u3002\u770b\u6765\u4e4b\u524d\u5bf9nginx\u7684\u914d\u7f6e\u8fd8\u662f\u4e0d\u591f\u4e86\u89e3\u3002<\/p>\n<p>\u6211\u81ea\u5df1\u7684\u914d\u7f6e\u5927\u81f4\u662f\u8fd9\u6837\uff1a<\/p>\n<pre class=\"\">#\u7981\u6b62\u7a7a\u4e3b\u673a\u5934\u8bbf\u95ee\nserver {\n    listen       80 default_server;\n    server_name _;\n    return 500;\n}\n\nserver {\n    listen       80;\n    server_name  youdomain.com www.yourdomain.com;\n    #\u4e0b\u9762\u8fd9\u6761\u89c4\u5b9a\u7ad9\u70b9\u6839\u76ee\u5f55\uff0c\u518d\u5f80\u4e0b\u7684\u914d\u7f6e\u5c31\u4ee5\u6b64\u4e3a\u6839\n    root \/usr\/share\/nginx\/siterootpath;\n    index index.php;\n\n    #charset koi8-r;\n    #\u4e0b\u9762\u8fd9\u53e5\u662f\u8bbf\u95eelog\uff0c\u6309\u9700\u5f00\u5173\n    #access_log  \/var\/log\/nginx\/log\/host.access.log  main;\n\n    #favicon\uff0c\u7ad9\u70b9\u7684\u56fe\u6807\uff0c\u53ef\u4ee5\u663e\u793a\u5728\u6d4f\u89c8\u5668\u6807\u9898\u680f\u4e0a\uff0c\u548crobots.txt\u4e24\u4e2a\u90fd\u4e0d\u9700\u8981log\n    location = \/favicon.ico {\n        log_not_found off;\n        access_log off;\n    }\n\n    location =\/robots.txt {\n        allow all;\n        log_not_found off;\n        access_log off;\n    }\n    # \u6240\u6709\u9759\u6001\u6587\u4ef6\u90fd\u76f4\u901a\uff0c\u89e3\u51b3\u4e86\u4e4b\u524djpg\u7b49\u6587\u4ef6\u5355\u72ec\u8bbe\u7f6e\u76f4\u901a\u7684\u95ee\u9898\uff0c\u53e6\u5916\u8fd8\u53ef\u4ee5\u76f4\u63a5\u652f\u6301\u56fa\u5b9a\u94fe\u63a5\n    location \/ {\n        try_files $uri $uri\/ \/index.php?$args;\n    }\n    \n    #\u81ea\u5b9a\u4e49404\n    #error_page  404              \/404.html;\n\n    #\u81ea\u5b9a\u4e49\u9519\u8bef\u9875\n    # redirect server error pages to the static page \/50x.html\n    #\n    error_page   500 502 503 504  \/50x.html;\n    location = \/50x.html {\n        root   \/usr\/share\/nginx\/html;\n    }\n\n    #\u5bf9\u4e0a\u4f20\u76ee\u5f55\u7981\u6b62\u6267\u884cphp\uff0c\u5e76\u963b\u6b62\u9664\u56fe\u7247\u4ee5\u5916\u7684\u4efb\u4f55\u6587\u4ef6\u7c7b\u578b\n    location \/wp-content\/uploads\/ {\n        if ($request_filename !~* \\.(jpg|jpeg|gif|png)$) {\n             return 403;\n        }\n        location ~ .*\\.(php)?$ {\n           deny all;\n        }\n    }\n    # php\u6587\u4ef6\u53d1\u9001\u5230php5-fpm\uff0c\u73b0\u5728\u8fd9\u4e00\u6bb5\u4e0d\u9700\u8981\u5199root\u76ee\u5f55\u4e86\n    #\n    location ~ \\.php$ {\n        #\u68c0\u67e5php\u6587\u4ef6\u662f\u5426\u771f\u5b9e\u5b58\u5728\uff0c\u9632\u6b62\u4f2a\u88c5\u6210jpg\u7684php\u7b49\n        if (!-f $document_root$fastcgi_script_name) {\n            return 404;\n        }\n        fastcgi_pass   unix:\/var\/run\/php5-fpm.sock;\n        fastcgi_index  index.php;\n        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;\n        include        fastcgi_params;\n    }\n\n    # deny access to .htaccess files, if Apache's document root\n    # concurs with nginx's one\n    #\n    location ~ \/\\.ht {\n        deny  all;\n    }\n    #js css \u56fe\u7247\u7b49\u6587\u4ef6\u6700\u5927\u5316\u6709\u6548\u671f\uff0c\u4e0d\u8bb0\u5f55\u8bbf\u95ee\n    location ~* \\.(js|css|png|jpg|jpeg|gif|ico)$ {\n        expires max;\n        log_not_found off;\n    }\n}\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>nginx\u5b98\u7f51\u63d0\u4f9b\u4e86\u5e38\u7528blog\/cms\u7b49\u7cfb\u7edf\u7684\u793a\u4f8b\u914d\u7f6e\u6587\u4ef6\u3002Wordpress\u7684\u5728\u8fd9\u91cc\u3002 \u57fa\u7840\u7684\u662f\u8fd9\u6837\uff1a server { ## Your website name goes here. server_name domain.tld; ## Your only path reference. root \/var\/www\/wordpress; ## This should be in your&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,12],"tags":[32,52],"class_list":["post-236","post","type-post","status-publish","format-standard","hentry","category-nginx","category-wordpress","tag-nginx","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.ji-zhi.net\/index.php?rest_route=\/wp\/v2\/posts\/236","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ji-zhi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ji-zhi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ji-zhi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ji-zhi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=236"}],"version-history":[{"count":0,"href":"https:\/\/www.ji-zhi.net\/index.php?rest_route=\/wp\/v2\/posts\/236\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ji-zhi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ji-zhi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ji-zhi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}