{"id":275,"date":"2017-10-18T22:55:56","date_gmt":"2017-10-18T14:55:56","guid":{"rendered":"http:\/\/kogasa.moe\/?p=275"},"modified":"2025-05-25T01:44:10","modified_gmt":"2025-05-24T17:44:10","slug":"apache-%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba%e9%85%8d%e7%bd%ae-ssl","status":"publish","type":"post","link":"https:\/\/flandre-scarlet.moe\/blog\/275\/","title":{"rendered":"Apache \u865a\u62df\u4e3b\u673a\u914d\u7f6e SSL"},"content":{"rendered":"<p>\u603b\u7ed3\u4e00\u4e0bLinux(\u6837\u4f8b\u4e3a centos)\u4e0a apache \u4e3a\u591a\u53f0\u865a\u62df\u4e3b\u673a\u542f\u7528 ssl \u8fde\u63a5\u7684\u8bbe\u7f6e\u3002<\/p>\n<p><!--more--><\/p>\n<h1>\u751f\u6210 SSL \u8bc1\u4e66<\/h1>\n<p>\u6211\u9009\u62e9\u7684\u662f Let&#8217;s Encrypt \u7684\u514d\u8d39 ssl \u8bc1\u4e66\u3002\u8d34\u4e2a<a href=\"https:\/\/github.com\/xdtianyu\/scripts\/tree\/master\/\" rel=\"noopener\" target=\"_blank\">Let&#8217;s Encrypt \u7684\u8bf4\u660e\u3002<\/a><\/p>\n<p>\u9996\u5148\u4f7f\u7528<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">wget https:\/\/raw.githubusercontent.com\/xdtianyu\/scripts\/master\/lets-encrypt\/letsencrypt.conf\r\nwget https:\/\/raw.githubusercontent.com\/xdtianyu\/scripts\/master\/lets-encrypt\/letsencrypt.sh\r\nchmod +x letsencrypt.sh<\/pre>\n<p>\u5c06\u4e24\u4e2a\u6587\u4ef6\u4e0b\u8f7d\u5230\u672c\u5730\u5e76\u8bbe\u7f6e\u6267\u884c\u6743\u9650\u3002<\/p>\n<p>\u4fee\u6539 letsencrypt.conf \u6587\u4ef6\u4e2d\u7684 DOMAIN_KEY\u3001DOMAIN_DIR \u548c DOMAINS \u5b57\u6bb5\u503c\u4e3a\u81ea\u5df1\u7684\u57df\u540d\u548c\u57df\u540d\u76ee\u5f55\u3002\u4fee\u6539\u5b8c\u6bd5\u540e\u6267\u884c &#8220;.\/letsencrypt.sh letsencrypt.conf&#8221; \u6765\u751f\u6210\u8bc1\u4e66\u6587\u4ef6\uff0c\u6267\u884c\u9700\u8981 python \u7684\u8fd0\u884c\u73af\u5883\uff0c\u5982\u679c\u6709\u63d0\u793a\u6709\u5305\u7f3a\u5931\u7684\u8bdd\u5347\u7ea7 python \u6216\u76f4\u63a5\u590d\u5236\u4e00\u4efd\u653e\u5230 python \u7684 lib \u76ee\u5f55\u5373\u53ef\u3002\u4e00\u822c\u57df\u540d\u76ee\u5f55\u8bbe\u7f6e\u6b63\u786e\uff0c\u4e14\u6709\u6743\u9650\u8bbf\u95ee\u57df\u540d\u5b50\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u7684\u8bdd\u57fa\u672c\u4f1a\u6210\u529f\u751f\u6210\u8bc1\u4e66\u3002\u6210\u529f\u540e\u5f97\u5230\u4e0b\u5217\u6587\u4ef6\uff1a<\/p>\n<ul>\n<li>example.crt<\/li>\n<li>example.csr<\/li>\n<li>example.chained.crt<\/li>\n<li>example.com.key<\/li>\n<li>letsencrypt-account.key<\/li>\n<li>lets-encrypt-x3-cross-signed.pem<\/li>\n<\/ul>\n<p>\u5176\u4e2d example.crt example.chained.crt \u548c example.com.key \u662f\u9700\u8981\u5199\u5230 apache \u7684\u914d\u7f6e\u4e2d\u53bb\u7684\u3002<\/p>\n<h1>\u8bbe\u7f6e Apache \u914d\u7f6e<\/h1>\n<p>\u5047\u8bbe\u5728\u4e3b\u673a\u4e0a\u5df2\u7ecf\u5b8c\u6210\u4e86 VirtualHost \u7684\u914d\u7f6e\u3002<\/p>\n<p>\u9996\u5148\u5982\u679c apache \u7684 lib \u4e2d\u6ca1\u6709 mod_ssl.so \u7684\u8bdd\u4f7f\u7528 &#8220;yum install mod_ssl&#8221; \u8fdb\u884c\u4e0b\u8f7d\u3002\u968f\u540e\u5728\u914d\u7f6e\u6587\u4ef6 httpd.conf \u4e2d\u52a0\u5165 &#8220;LoadModule ssl_module \/usr\/lib\/httpd\/modules\/mod_ssl.so&#8221; \u5373\u53ef\u3002<\/p>\n<p>\u5982\u679c\u4f60\u7684\u4e3b\u673a\u6ca1\u6709\u50cf httpd-ssl.conf \u8fd9\u6837\u7684\u6587\u4ef6\u7684\u8bdd\uff0c\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u52a0\u5165\u5982\u4e0b\u7684\u914d\u7f6e\u5185\u5bb9\uff1a<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\nAddType application\/x-x509-ca-cert .crt\r\nAddType application\/x-pkcs7-crl    .crl\r\nSSLCipherSuite HIGH:MEDIUM:!MD5:!RC4\r\nSSLProxyCipherSuite HIGH:MEDIUM:!MD5:!RC4\r\nSSLProtocol all -SSLv2 -SSLv3\r\nSSLProxyProtocol all -SSLv2 -SSLv3\r\nSSLSessionCache        &quot;shmcb:\/path\/to\/apache\/logs\/ssl_scache(512000)&quot;\r\nSSLSessionCacheTimeout  300\r\nSSLPassPhraseDialog  builtin\r\nSSLMutex  default\r\n\r\nListen 443\r\nNameVirtualHost *:443\r\n&lt;VirtualHost *:443&gt;\r\n    ServerAdmin webmaster@example.com\r\n    DocumentRoot \u201c\/path\/to\/example.com\u201d\r\n    ServerName example.com:443\r\n    &lt;Directory \u201c\/path\/to\/example.com\u201d&gt;\r\n        SetOutputFilter DEFLATE\r\n        Options FollowSymLinks\r\n        AllowOverride All\r\n        Order allow,deny\r\n        Allow from all\r\n        DirectoryIndex index.html index.php\r\n    &lt;\/Directory&gt;\r\n    SSLEngine on\r\n    SSLCertificateFile \/path\/to\/example.crt\r\n    SSLCertificateKeyFile \/path\/to\/example.com.key\r\n    SSLCertificateChainFile \/path\/to\/example.chained.crt\r\n&lt;\/VirtualHost&gt;<\/pre>\n<p>\u4ee5\u4e0a\u8def\u5f84\u81ea\u884c\u66ff\u6362\u6210\u6b63\u786e\u7684\u8def\u5f84\uff0c\u8fd9\u6837\u5c31\u5b8c\u6210\u4e86\u57fa\u672c\u7684&nbsp;ssl&nbsp;\u8bbe\u7f6e\u4e86\u3002<\/p>\n<p>\u5982\u679c\u4f60\u7684\u4e3b\u673a\u5b58\u5728\u4e0a\u8ff0\u6587\u4ef6\uff08httpd-ssl.conf\uff09\u7684\u8bdd\uff0c\u4e00\u822c\u53ea\u8981\u5728\u4e3b\u914d\u7f6e\u6587\u4ef6\u4e2d\u53bb\u6389 &#8220;Include conf\/extra\/httpd-ssl.conf&#8221; \u524d\u7684\u6ce8\u91ca\u7b26\u53f7\u5373\u53ef\uff0c\u540c\u65f6\u4e5f\u8981\u53bb\u6389 &#8220;LoadModule ssl_module modules\/mod_ssl.so&#8221; \u524d\u7684\u6ce8\u91ca\u3002\u5e76\u5c06\u5176\u4e2d\u7684\u9ed8\u8ba4\u865a\u62df\u4e3b\u673a\u914d\u7f6e\u4fee\u6539\u4e3a\u81ea\u5df1\u7684\u914d\u7f6e\uff0c\u6216\u8005\u5c31\u8fd9\u6837\u5c06\u6240\u6709\u8def\u5f84\u8bbe\u4e3a\u4e0d\u53ef\u8bbf\u95ee\u540e\u7559\u4f5c\u9ed8\u8ba4\u54cd\u5e94\u7684\u4e3b\u673a\u3002<\/p>\n<h1> \u8bbe\u7f6e .htaccess \u8f6c\u53d1<\/h1>\n<p>\u5728 .htaccess \u4e2d\u6dfb\u52a0\u8f6c\u53d1\u89c4\u5219<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">RewriteCond %{HTTPS} !=on\r\nRewriteRule ^(.*) https:\/\/%{SERVER_NAME}\/$1 &#x5B;R,L]<\/pre>\n<\/p>\n<p>\u6700\u540e\u91cd\u542f apache \u670d\u52a1\u3002<\/p>\n<p>\u53ef\u4ee5\u52a0\u4e2acron \u5b9a\u65f6\u4efb\u52a1\uff0c\u6bcf\u4e2a\u6708\u81ea\u52a8\u66f4\u65b0\u4e00\u6b21\u8bc1\u4e66\uff0c\u53ef\u4ee5\u5728\u811a\u672c\u6700\u540e\u52a0\u5165 \/etc\/init.d\/httpd restart \u7b49\u91cd\u65b0\u52a0\u8f7d\u670d\u52a1\u3002<\/br><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">0 0 1 * * \/etc\/nginx\/certs\/letsencrypt.sh \/etc\/nginx\/certs\/letsencrypt.conf &gt;&gt; \/var\/log\/lets-encrypt.log 2&gt;&amp;1<\/pre>\n<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/br>\u8d34\u4e00\u4e2a apache \u865a\u62df\u4e3b\u673a\u5339\u914d\u7684\u53c2\u8003\uff1a<a href=\"http:\/\/man.chinaunix.net\/newsoft\/ApacheManual\/vhosts\/details.html\" rel=\"noopener\" target=\"_blank\">\u6df1\u5165\u7814\u7a76\u865a\u62df\u4e3b\u673a\u7684\u5339\u914d<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u603b\u7ed3\u4e00\u4e0bLinux(\u6837\u4f8b\u4e3a centos)\u4e0a apache \u4e3a\u591a\u53f0\u865a\u62df\u4e3b\u673a\u542f\u7528 ssl \u8fde\u63a5\u7684\u8bbe\u7f6e\u3002&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/flandre-scarlet.moe\/blog\/275\/\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[85],"tags":[6,8,15,20,21],"class_list":["post-275","post","type-post","status-publish","format-standard","hentry","category-programs","tag-apache","tag-centos","tag-https","tag-ssl","tag-virtualhost"],"_links":{"self":[{"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/posts\/275","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/comments?post=275"}],"version-history":[{"count":1,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/posts\/275\/revisions"}],"predecessor-version":[{"id":2175,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/posts\/275\/revisions\/2175"}],"wp:attachment":[{"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/media?parent=275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/categories?post=275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/tags?post=275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}