{"id":43080,"date":"2024-10-04T16:03:12","date_gmt":"2024-10-04T08:03:12","guid":{"rendered":"https:\/\/server.hk\/cnblog\/43080\/"},"modified":"2024-10-04T16:03:12","modified_gmt":"2024-10-04T08:03:12","slug":"centos-7-%e5%ae%89%e8%a3%9d%e9%83%a8%e7%bd%b2-apache-%e7%b6%b2%e7%ab%99%e5%be%8c%e9%85%8d%e7%bd%ae%e8%a9%b3%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/43080\/","title":{"rendered":"CentOS 7 \u5b89\u88dd\u90e8\u7f72 Apache \u7db2\u7ad9\u5f8c\u914d\u7f6e\u8a73\u89e3"},"content":{"rendered":"<h1 id=\"centos-7-%e5%ae%89%e8%a3%9d%e9%83%a8%e7%bd%b2-apache-%e7%b6%b2%e7%ab%99%e5%be%8c%e9%85%8d%e7%bd%ae%e8%a9%b3%e8%a7%a3-bAoxAFREWZ\">CentOS 7 \u5b89\u88dd\u90e8\u7f72 Apache \u7db2\u7ad9\u5f8c\u914d\u7f6e\u8a73\u89e3<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0cApache \u4f5c\u70ba\u6700\u6d41\u884c\u7684\u7db2\u9801\u4f3a\u670d\u5668\u4e4b\u4e00\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u7db2\u7ad9\u7684\u642d\u5efa\u3002\u672c\u6587\u5c07\u8a73\u7d30\u4ecb\u7d39\u5982\u4f55\u5728 CentOS 7 \u4e0a\u5b89\u88dd\u548c\u914d\u7f6e Apache \u7db2\u7ad9\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u6700\u4f73\u5be6\u8e10\u548c\u914d\u7f6e\u6280\u5de7\u3002<\/p>\n<h2 id=\"%e4%b8%80%e3%80%81%e5%ae%89%e8%a3%9d-apache-bAoxAFREWZ\">\u4e00\u3001\u5b89\u88dd Apache<\/h2>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u78ba\u4fdd\u60a8\u7684 CentOS 7 \u7cfb\u7d71\u5df2\u7d93\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u66f4\u65b0\uff1a<\/p>\n<pre><code>sudo yum update<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd Apache\uff08httpd\uff09\uff1a<\/p>\n<pre><code>sudo yum install httpd<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u555f\u52d5 Apache \u670d\u52d9\u4e26\u8a2d\u7f6e\u5176\u5728\u7cfb\u7d71\u555f\u52d5\u6642\u81ea\u52d5\u555f\u52d5\uff1a<\/p>\n<pre><code>sudo systemctl start httpd\nsudo systemctl enable httpd<\/code><\/pre>\n<h2 id=\"%e4%ba%8c%e3%80%81%e9%85%8d%e7%bd%ae%e9%98%b2%e7%81%ab%e7%89%86-bAoxAFREWZ\">\u4e8c\u3001\u914d\u7f6e\u9632\u706b\u7246<\/h2>\n<p>\u5728 CentOS 7 \u4e2d\uff0c\u9ed8\u8a8d\u7684\u9632\u706b\u7246\u662f firewalld\u3002\u60a8\u9700\u8981\u5141\u8a31 HTTP \u548c HTTPS \u6d41\u91cf\u901a\u904e\u9632\u706b\u7246\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u914d\u7f6e\uff1a<\/p>\n<pre><code>sudo firewall-cmd --permanent --add-service=http\nsudo firewall-cmd --permanent --add-service=https\nsudo firewall-cmd --reload<\/code><\/pre>\n<h2 id=\"%e4%b8%89%e3%80%81%e6%aa%a2%e6%9f%a5-apache-%e7%8b%80%e6%85%8b-bAoxAFREWZ\">\u4e09\u3001\u6aa2\u67e5 Apache \u72c0\u614b<\/h2>\n<p>\u8981\u78ba\u8a8d Apache \u662f\u5426\u6b63\u5e38\u904b\u884c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5\u5176\u72c0\u614b\uff1a<\/p>\n<pre><code>sudo systemctl status httpd<\/code><\/pre>\n<p>\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u60a8\u61c9\u8a72\u6703\u770b\u5230 Apache \u6b63\u5728\u904b\u884c\u7684\u6d88\u606f\u3002\u63a5\u4e0b\u4f86\uff0c\u60a8\u53ef\u4ee5\u5728\u700f\u89bd\u5668\u4e2d\u8f38\u5165\u4f3a\u670d\u5668\u7684 IP \u5730\u5740\uff0c\u61c9\u8a72\u80fd\u770b\u5230 Apache \u7684\u9810\u8a2d\u6b61\u8fce\u9801\u9762\u3002<\/p>\n<h2 id=\"%e5%9b%9b%e3%80%81%e9%85%8d%e7%bd%ae%e8%99%9b%e6%93%ac%e4%b8%bb%e6%a9%9f-bAoxAFREWZ\">\u56db\u3001\u914d\u7f6e\u865b\u64ec\u4e3b\u6a5f<\/h2>\n<p>\u5982\u679c\u60a8\u9700\u8981\u5728\u540c\u4e00\u53f0\u4f3a\u670d\u5668\u4e0a\u904b\u884c\u591a\u500b\u7db2\u7ad9\uff0c\u53ef\u4ee5\u4f7f\u7528\u865b\u64ec\u4e3b\u6a5f\u4f86\u5be6\u73fe\u3002\u9996\u5148\uff0c\u5275\u5efa\u4e00\u500b\u65b0\u7684\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo vi \/etc\/httpd\/conf.d\/example.com.conf<\/code><\/pre>\n<p>\u5728\u8a72\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u5167\u5bb9\uff1a<\/p>\n<pre><code>&lt;VirtualHost *:80&gt;\n    ServerName example.com\n    ServerAlias www.example.com\n    DocumentRoot \/var\/www\/example.com\/public_html\n    ErrorLog \/var\/www\/example.com\/error.log\n    CustomLog \/var\/www\/example.com\/requests.log combined\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u5275\u5efa\u7db2\u7ad9\u7684\u6839\u76ee\u9304\u4e26\u8a2d\u7f6e\u9069\u7576\u7684\u6b0a\u9650\uff1a<\/p>\n<pre><code>sudo mkdir -p \/var\/www\/example.com\/public_html\nsudo chown -R $USER:$USER \/var\/www\/example.com\/public_html\nsudo chmod -R 755 \/var\/www<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u60a8\u53ef\u4ee5\u5728\u8a72\u76ee\u9304\u4e2d\u653e\u7f6e\u60a8\u7684\u7db2\u7ad9\u6587\u4ef6\u3002\u5b8c\u6210\u5f8c\uff0c\u91cd\u555f Apache \u4ee5\u61c9\u7528\u66f4\u6539\uff1a<\/p>\n<pre><code>sudo systemctl restart httpd<\/code><\/pre>\n<h2 id=\"%e4%ba%94%e3%80%81%e5%ae%89%e8%a3%9d-ssl-%e8%ad%89%e6%9b%b8-bAoxAFREWZ\">\u4e94\u3001\u5b89\u88dd SSL \u8b49\u66f8<\/h2>\n<p>\u70ba\u4e86\u63d0\u9ad8\u7db2\u7ad9\u7684\u5b89\u5168\u6027\uff0c\u5efa\u8b70\u70ba\u60a8\u7684\u7db2\u7ad9\u5b89\u88dd SSL \u8b49\u66f8\u3002\u53ef\u4ee5\u4f7f\u7528 Let&#8217;s Encrypt \u63d0\u4f9b\u7684\u514d\u8cbb SSL \u8b49\u66f8\u3002\u9996\u5148\uff0c\u5b89\u88dd Certbot\uff1a<\/p>\n<pre><code>sudo yum install epel-release\nsudo yum install certbot python2-certbot-apache<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u7372\u53d6 SSL \u8b49\u66f8\uff1a<\/p>\n<pre><code>sudo certbot --apache -d example.com -d www.example.com<\/code><\/pre>\n<p>\u6309\u7167\u63d0\u793a\u5b8c\u6210\u8b49\u66f8\u7684\u5b89\u88dd\uff0c\u4e26\u78ba\u4fdd\u5728 Apache \u914d\u7f6e\u4e2d\u555f\u7528 HTTPS\u3002<\/p>\n<h2 id=\"%e5%85%ad%e3%80%81%e6%9c%80%e4%bd%b3%e5%af%a6%e8%b8%90-bAoxAFREWZ\">\u516d\u3001\u6700\u4f73\u5be6\u8e10<\/h2>\n<ul>\n<li>\u5b9a\u671f\u66f4\u65b0 Apache \u548c\u7cfb\u7d71\uff0c\u4ee5\u78ba\u4fdd\u5b89\u5168\u6027\u3002<\/li>\n<li>\u4f7f\u7528\u5f37\u5bc6\u78bc\u548c\u9069\u7576\u7684\u6b0a\u9650\u4f86\u4fdd\u8b77\u60a8\u7684\u7db2\u7ad9\u6587\u4ef6\u3002<\/li>\n<li>\u5b9a\u671f\u5099\u4efd\u60a8\u7684\u7db2\u7ad9\u6578\u64da\u548c\u914d\u7f6e\u6587\u4ef6\u3002<\/li>\n<li>\u76e3\u63a7\u4f3a\u670d\u5668\u6027\u80fd\u548c\u6d41\u91cf\uff0c\u4ee5\u4fbf\u53ca\u6642\u8abf\u6574\u8cc7\u6e90\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-bAoxAFREWZ\">\u7e3d\u7d50<\/h2>\n<p>\u5728 CentOS 7 \u4e0a\u5b89\u88dd\u548c\u914d\u7f6e Apache \u7db2\u7ad9\u662f\u4e00\u500b\u76f8\u5c0d\u7c21\u55ae\u7684\u904e\u7a0b\u3002\u901a\u904e\u4e0a\u8ff0\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u6210\u529f\u642d\u5efa\u4e00\u500b\u7a69\u5b9a\u7684\u7db2\u7ad9\u74b0\u5883\u3002\u82e5\u60a8\u9700\u8981\u66f4\u9ad8\u6548\u7684\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u670d\u52d9\uff0c\u4ee5\u7372\u5f97\u66f4\u597d\u7684\u6027\u80fd\u548c\u53ef\u9760\u6027\u3002\u7121\u8ad6\u662f\u500b\u4eba\u7db2\u7ad9\u9084\u662f\u5546\u696d\u61c9\u7528\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a> \u5c0d\u65bc\u7db2\u7ad9\u7684\u6210\u529f\u81f3\u95dc\u91cd\u8981\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8a73\u7d30\u6307\u5357\uff0c\u6559\u60a8\u5982\u4f55\u5728 CentOS 7 \u4e0a\u5b89\u88dd\u90e8\u7f72 Apache \u7db2\u7ad9\uff0c\u4e26\u9032\u884c\u5fc5\u8981\u7684\u914d\u7f6e\uff0c\u78ba\u4fdd\u7db2\u7ad9\u9806\u5229\u904b\u884c\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-43080","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43080","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=43080"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43080\/revisions"}],"predecessor-version":[{"id":43081,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43080\/revisions\/43081"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=43080"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=43080"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=43080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}