{"title":"Apache\u5b89\u88c5\u8bc1\u4e66\u6559\u7a0b","content":"<h2 style=\"text-align: start;\">\u9002\u7528\u73af\u5883<\/h2><ul><li style=\"text-align: start;\">Apache \u670d\u52a1\u5668<\/li><li style=\"text-align: start;\">Phpstudy<\/li><li style=\"text-align: start;\">Wamp<\/li><li style=\"text-align: start;\">Lamp<\/li><\/ul><h2 style=\"text-align: start;\">\u51c6\u5907\u5de5\u4f5c<\/h2><p style=\"text-align: start;\">\u5728\u5b89\u88c5 SSL \u8bc1\u4e66\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\uff1a<\/p><ol><li style=\"text-align: start;\">\u5df2\u7ecf\u83b7\u53d6\u4e86 SSL \u8bc1\u4e66\u6587\u4ef6<\/li><li style=\"text-align: start;\">Apache \u5df2\u6b63\u786e\u5b89\u88c5\u5e76\u53ef\u4ee5\u6b63\u5e38\u8bbf\u95ee<\/li><li style=\"text-align: start;\">\u5df2\u5b89\u88c5 mod_ssl \u6a21\u5757<\/li><li style=\"text-align: start;\">\u786e\u4fdd Apache \u7248\u672c\u517c\u5bb9\u6027<\/li><\/ol><h2 style=\"text-align: start;\">\u914d\u7f6e\u793a\u4f8b<\/h2><pre><code >&lt;VirtualHost *:443&gt;\r\n    ServerName yourdomain.com\r\n    DocumentRoot \/var\/www\/html\r\n    SSLEngine on\r\n    SSLCertificateFile \/path\/to\/yourdomain.com.crt\r\n    SSLCertificateKeyFile \/path\/to\/yourdomain.com.key\r\n    SSLCertificateChainFile \/path\/to\/yourdomain.com-ca-bundle.crt\r\n&lt;\/VirtualHost&gt;<\/code><\/pre><p><br><\/p><h2 style=\"text-align: start;\">\u5b89\u88c5\u6b65\u9aa4<\/h2><h3 style=\"text-align: start;\">1. \u51c6\u5907\u8bc1\u4e66\u6587\u4ef6<\/h3><p style=\"text-align: start;\">Apache \u683c\u5f0f\u7684\u8bc1\u4e66\u89e3\u538b\u540e\u5e94\u5305\u542b\u4e09\u4e2a\u6587\u4ef6:<\/p><pre><code >domain.com.crt    (\u57df\u540d\u8bc1\u4e66\uff0c\u4e5f\u53ef\u80fd\u662fpem\u683c\u5f0f)\r\ndomain.com.key    (\u79c1\u94a5\u6587\u4ef6)\r\ndomain.com-ca-bundle.crt (\u6839\u8bc1\u4e66\u94fe\uff0c\u4e5f\u53ef\u80fd\u662f\u5176\u4ed6\u6587\u4ef6\u540d\uff0c\u4e00\u822c\u5e26\u6709 ca \u6216\u8005 chain)<\/code><\/pre><p><br><\/p><h3 style=\"text-align: start;\">2. \u653e\u7f6e\u8bc1\u4e66\u6587\u4ef6<\/h3><p style=\"text-align: start;\">\u5c06\u8bc1\u4e66\u6587\u4ef6\u653e\u5728 apache \u7684 conf\/ssl \u76ee\u5f55\u4e0b\uff0c\u5982\u679c conf \u76ee\u5f55\u91cc\u6ca1\u6709 ssl \u76ee\u5f55\uff0c\u53ef\u4ee5\u65b0\u5efa\u4e00\u4e2a\u3002 \u653e\u5728 conf\/ssl \u53ef\u4ee5\u7528\u76f8\u5bf9\u8def\u5f84\uff0c\u5176\u4ed6\u4f4d\u7f6e\u9700\u8981\u7528\u7edd\u5bf9\u8def\u5f84\u3002<\/p><h3 style=\"text-align: start;\">3. \u914d\u7f6e\u865a\u62df\u4e3b\u673a<\/h3><p style=\"text-align: start;\">\u627e\u5230\u7ad9\u70b9\u7684 80 \u7aef\u53e3\u914d\u7f6e\uff0c\u4e00\u822c\u5728 conf\/vhosts.conf \u6587\u4ef6\u91cc(\u6709\u7684\u662f\u5728 conf\/extra\/httpd-vhosts.conf)\uff0c\u4f8b\u5982\uff1a<\/p><pre><code >&lt;VirtualHost *:80&gt;\r\n    ServerName yourdomain.com\r\n    ServerAlias www.yourdomain.com\r\n    DocumentRoot \/www\/wwwroot\r\n    #\u5176\u4ed6\u7684\u914d\u7f6e\u4fe1\u606f\u00b7\u00b7\u00b7\r\n&lt;\/VirtualHost&gt;<\/code><\/pre><h3 style=\"text-align: start;\">4. \u914d\u7f6e HTTPS \u865a\u62df\u4e3b\u673a<\/h3><p style=\"text-align: start;\">\u5728 vhosts.conf \u540c\u7ea7\u76ee\u5f55\u91cc\uff0c\u65b0\u5efa\u4e00\u4e2a vhosts-https.conf \u6587\u4ef6\uff0c\u590d\u5236 80 \u7aef\u53e3\u914d\u7f6e\u8fc7\u6765\u8fdb\u884c\u4fee\u6539\uff0c\u6dfb\u52a0 ssl \u914d\u7f6e\uff1a<\/p><pre><code >&lt;VirtualHost *:443&gt;\r\n    ServerName yourdomain.com\r\n    ServerAlias www.yourdomain.com\r\n    DocumentRoot \/www\/wwwroot\r\n    #\u4e0d\u540c\u8bc1\u4e66\u6587\u4ef6\u540d\u548c\u540e\u7f00\u53ef\u80fd\u4e0d\u540c  \u4fee\u6539\u6587\u4ef6\u540d\u4e3aapache\u76843\u4e2a\u5b9e\u9645\u6587\u4ef6\u540d\u5373\u53ef\r\n    SSLEngine on\r\n    SSLCertificateFile      conf\/ssl\/yourdomain.com.crt\r\n    SSLCertificateKeyFile   conf\/ssl\/yourdomain.com.key\r\n    SSLCertificateChainFile conf\/ssl\/yourdomain.com-ca-bundle.crt\r\n    #\u5176\u4ed6\u7684\u914d\u7f6e\u4fe1\u606f\u00b7\u00b7\u00b7\r\n&lt;\/VirtualHost&gt;<\/code><\/pre><h3 style=\"text-align: start;\">5. \u4fee\u6539\u4e3b\u914d\u7f6e\u6587\u4ef6<\/h3><p style=\"text-align: start;\">\u6253\u5f00 conf \u76ee\u5f55\u91cc\u7684 httpd.conf \u6587\u4ef6\uff0c\u627e\u5230 Include conf\/vhosts.conf \u5728\u4e0b\u9762\u6dfb\u52a0\uff1a<\/p><pre><code >#\u8fd9\u4e00\u884c\u4e00\u822c\u5728\u6587\u4ef6\u540e\u9762\uff0c\u4ece\u540e\u9762\u66f4\u5bb9\u6613\u627e\u5230\r\nInclude conf\/vhosts.conf\r\n#\u4e0b\u9762\u662f\u6dfb\u52a0\u7684\r\nInclude conf\/vhosts-https.conf\r\nListen 443\r\nSSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE\r\nSSLProtocol All -SSLv2 -SSLv3\r\nSSLHonorCipherOrder On<\/code><\/pre><p style=\"text-align: start;\"><br><\/p><h3 style=\"text-align: start;\">6. \u68c0\u67e5 SSL \u6a21\u5757<\/h3><h4 style=\"text-align: start;\">Linux \u7cfb\u7edf\u68c0\u67e5\u65b9\u6cd5<\/h4><p style=\"text-align: start;\">\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5 mod_ssl.so \u6a21\u5757\uff1a<\/p><p style=\"text-align: start;\"><br><\/p><pre style=\"text-align: left;\"><code style=\"text-align: left;\">find \/ -name mod_ssl.so | grep modules\/mod_ssl.so<\/code><\/pre><p style=\"text-align: start;\">\u5982\u679c\u6ca1\u6709\u627e\u5230\uff0c\u53ef\u4ee5\u5b89\u88c5\uff1a<\/p><ul><li style=\"text-align: start;\">CentOS\/Redhat:<\/li><li style=\"text-align: start;\"><\/li><li style=\"text-align: start;\"><\/li><\/ul><pre style=\"text-align: left;\"><code style=\"text-align: left;\">yum install mod_ssl<\/code><\/pre><ul><li style=\"text-align: start;\">Debian\/Ubuntu:<\/li><li style=\"text-align: start;\"><\/li><li style=\"text-align: start;\"><\/li><\/ul><pre style=\"text-align: left;\"><code style=\"text-align: left;\">sudo a2enmod ssl\nsudo service apache2 restart<\/code><\/pre><p style=\"text-align: start;\">\u68c0\u67e5 httpd.conf \u6587\u4ef6\u662f\u5426\u52a0\u8f7d ssl \u6a21\u5757\uff1a<\/p><p style=\"text-align: start;\"><br><\/p><pre style=\"text-align: left;\"><code style=\"text-align: left;\">LoadModule ssl_module modules\/mod_ssl.so  #\u5982\u679c\u524d\u9762\u6709#\u53f7\u8981\u53bb\u6389<\/code><\/pre><h3 style=\"text-align: start;\">7. \u91cd\u542f Apache<\/h3><p style=\"text-align: start;\">\u914d\u7f6e\u5b8c\u6210\u540e\u91cd\u542f Apache \u4f7f\u5176\u751f\u6548\uff1a<\/p><p style=\"text-align: start;\"><br><\/p><pre style=\"text-align: left;\"><code style=\"text-align: left;\"># Linux\nservice httpd restart\n# \u6216\napachectl restart\n\n# Windows\nnet stop apache\nnet start apache<\/code><\/pre><h3 style=\"text-align: start;\">8. \u6d4b\u8bd5\u914d\u7f6e<\/h3><p style=\"text-align: start;\">\u6d4b\u8bd5 https \u662f\u5426\u53ef\u4ee5\u8bbf\u95ee<\/p><h2 style=\"text-align: start;\">\u5e38\u89c1\u95ee\u9898<\/h2><ol><li style=\"text-align: start;\">Apache \u65e0\u6cd5\u542f\u52a8\u68c0\u67e5\u662f\u5426\u52a0\u8f7d\u4e86 mod_ssl.so \u6a21\u5757\u68c0\u67e5\u8bc1\u4e66\u6587\u4ef6\u8def\u5f84\u662f\u5426\u6b63\u786e\u68c0\u67e5\u8bc1\u4e66\u6587\u4ef6\u6743\u9650\u662f\u5426\u6b63\u786e<\/li><li style=\"text-align: start;\">HTTPS \u8bbf\u95ee\u5931\u8d25\u68c0\u67e5 443 \u7aef\u53e3\u662f\u5426\u5f00\u653e\u68c0\u67e5\u8bc1\u4e66\u662f\u5426\u8fc7\u671f\u68c0\u67e5\u8bc1\u4e66\u57df\u540d\u662f\u5426\u5339\u914d<\/li><li style=\"text-align: start;\">\u8bc1\u4e66\u94fe\u4e0d\u5b8c\u6574\u786e\u4fdd SSLCertificateChainFile \u6307\u5411\u6b63\u786e\u7684\u8bc1\u4e66\u94fe\u6587\u4ef6\u786e\u4fdd\u8bc1\u4e66\u94fe\u6587\u4ef6\u5305\u542b\u5b8c\u6574\u7684\u8bc1\u4e66\u94fe<\/li><\/ol><p><br><\/p><p><br><\/p><p><br><\/p><p><br><\/p>","updated_at":"2026-07-22 12:29:52"}