{"id":43814,"date":"2024-10-06T10:44:14","date_gmt":"2024-10-06T02:44:14","guid":{"rendered":"https:\/\/server.hk\/cnblog\/43814\/"},"modified":"2024-10-06T10:44:14","modified_gmt":"2024-10-06T02:44:14","slug":"centos-7-%e9%85%8d%e7%bd%ae-httpd-%e8%99%9b%e6%93%ac%e4%b8%bb%e6%a9%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/43814\/","title":{"rendered":"CentOS 7 \u914d\u7f6e httpd \u865b\u64ec\u4e3b\u6a5f"},"content":{"rendered":"<h1 id=\"centos-7-%e9%85%8d%e7%bd%ae-httpd-%e8%99%9b%e6%93%ac%e4%b8%bb%e6%a9%9f-HYvdSRmZpY\">CentOS 7 \u914d\u7f6e httpd \u865b\u64ec\u4e3b\u6a5f<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u865b\u64ec\u4e3b\u6a5f\u6280\u8853\u5df2\u6210\u70ba\u7db2\u7ad9\u6258\u7ba1\u7684\u4e3b\u6d41\u9078\u64c7\u3002CentOS 7 \u4f5c\u70ba\u4e00\u500b\u7a69\u5b9a\u4e14\u5ee3\u6cdb\u4f7f\u7528\u7684 Linux \u767c\u884c\u7248\uff0c\u63d0\u4f9b\u4e86\u5f37\u5927\u7684\u652f\u6301\u4f86\u914d\u7f6e\u548c\u7ba1\u7406 httpd\uff08Apache HTTP Server\uff09\u865b\u64ec\u4e3b\u6a5f\u3002\u672c\u6587\u5c07\u8a73\u7d30\u4ecb\u7d39\u5982\u4f55\u5728 CentOS 7 \u4e0a\u914d\u7f6e httpd \u865b\u64ec\u4e3b\u6a5f\uff0c\u5e6b\u52a9\u7528\u6236\u66f4\u597d\u5730\u7ba1\u7406\u5176\u7db2\u7ad9\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-httpd-HYvdSRmZpY\">\u5b89\u88dd httpd<\/h2>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u78ba\u4fdd\u5df2\u5b89\u88dd httpd\u3002\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u4f86\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo yum install httpd<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u555f\u52d5 httpd \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=\"%e9%85%8d%e7%bd%ae%e8%99%9b%e6%93%ac%e4%b8%bb%e6%a9%9f-HYvdSRmZpY\">\u914d\u7f6e\u865b\u64ec\u4e3b\u6a5f<\/h2>\n<p>\u5728\u914d\u7f6e\u865b\u64ec\u4e3b\u6a5f\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u78ba\u4fdd\u5df2\u7d93\u5275\u5efa\u4e86\u7db2\u7ad9\u7684\u76ee\u9304\u7d50\u69cb\u3002\u5047\u8a2d\u6211\u5011\u8981\u70ba\u4e00\u500b\u540d\u70ba example.com \u7684\u7db2\u7ad9\u914d\u7f6e\u865b\u64ec\u4e3b\u6a5f\uff0c\u60a8\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9a5f\u9032\u884c\uff1a<\/p>\n<h3 id=\"1-%e5%89%b5%e5%bb%ba%e7%b6%b2%e7%ab%99%e7%9b%ae%e9%8c%84-HYvdSRmZpY\">1. \u5275\u5efa\u7db2\u7ad9\u76ee\u9304<\/h3>\n<pre><code>sudo mkdir -p \/var\/www\/example.com\/public_html<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u8a2d\u7f6e\u76ee\u9304\u7684\u6b0a\u9650\uff1a<\/p>\n<pre><code>sudo chown -R $USER:$USER \/var\/www\/example.com\/public_html<\/code><\/pre>\n<h3 id=\"2-%e5%89%b5%e5%bb%ba%e4%b8%80%e5%80%8b%e6%b8%ac%e8%a9%a6%e9%a0%81%e9%9d%a2-HYvdSRmZpY\">2. \u5275\u5efa\u4e00\u500b\u6e2c\u8a66\u9801\u9762<\/h3>\n<p>\u5728 public_html \u76ee\u9304\u4e2d\u5275\u5efa\u4e00\u500b\u7c21\u55ae\u7684 HTML \u6587\u4ef6\u4ee5\u78ba\u8a8d\u914d\u7f6e\u662f\u5426\u6210\u529f\uff1a<\/p>\n<pre><code>echo &quot;Welcome to Example.com!&quot; &gt; \/var\/www\/example.com\/public_html\/index.html<\/code><\/pre>\n<h3 id=\"3-%e9%85%8d%e7%bd%ae%e8%99%9b%e6%93%ac%e4%b8%bb%e6%a9%9f%e6%96%87%e4%bb%b6-HYvdSRmZpY\">3. \u914d\u7f6e\u865b\u64ec\u4e3b\u6a5f\u6587\u4ef6<\/h3>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u5275\u5efa\u4e00\u500b\u865b\u64ec\u4e3b\u6a5f\u914d\u7f6e\u6587\u4ef6\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5275\u5efa\u4e00\u500b\u65b0\u7684\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo nano \/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    ServerAdmin webmaster@example.com\n    ServerName example.com\n    ServerAlias www.example.com\n    DocumentRoot \/var\/www\/example.com\/public_html\n    ErrorLog \/var\/log\/httpd\/example.com-error.log\n    CustomLog \/var\/log\/httpd\/example.com-access.log combined\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n<h3 id=\"4-%e6%aa%a2%e6%9f%a5%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6%e7%9a%84%e6%ad%a3%e7%a2%ba%e6%80%a7-HYvdSRmZpY\">4. \u6aa2\u67e5\u914d\u7f6e\u6587\u4ef6\u7684\u6b63\u78ba\u6027<\/h3>\n<p>\u5728\u91cd\u65b0\u555f\u52d5 httpd \u670d\u52d9\u4e4b\u524d\uff0c\u6aa2\u67e5\u914d\u7f6e\u6587\u4ef6\u662f\u5426\u6b63\u78ba\uff1a<\/p>\n<pre><code>sudo apachectl configtest<\/code><\/pre>\n<p>\u5982\u679c\u6c92\u6709\u932f\u8aa4\uff0c\u60a8\u5c07\u770b\u5230 \u201cSyntax OK\u201d \u7684\u63d0\u793a\u3002<\/p>\n<h3 id=\"5-%e9%87%8d%e6%96%b0%e5%95%9f%e5%8b%95-httpd-%e6%9c%8d%e5%8b%99-HYvdSRmZpY\">5. \u91cd\u65b0\u555f\u52d5 httpd \u670d\u52d9<\/h3>\n<p>\u6700\u5f8c\uff0c\u91cd\u65b0\u555f\u52d5 httpd \u670d\u52d9\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\uff1a<\/p>\n<pre><code>sudo systemctl restart httpd<\/code><\/pre>\n<h2 id=\"%e9%98%b2%e7%81%ab%e7%89%86%e8%a8%ad%e7%bd%ae-HYvdSRmZpY\">\u9632\u706b\u7246\u8a2d\u7f6e<\/h2>\n<p>\u5982\u679c\u60a8\u7684\u7cfb\u7d71\u555f\u7528\u4e86\u9632\u706b\u7246\uff0c\u60a8\u9700\u8981\u5141\u8a31 HTTP \u548c HTTPS \u6d41\u91cf\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u8a2d\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=\"%e6%b8%ac%e8%a9%a6%e8%99%9b%e6%93%ac%e4%b8%bb%e6%a9%9f-HYvdSRmZpY\">\u6e2c\u8a66\u865b\u64ec\u4e3b\u6a5f<\/h2>\n<p>\u73fe\u5728\uff0c\u60a8\u53ef\u4ee5\u5728\u700f\u89bd\u5668\u4e2d\u8f38\u5165 http:\/\/example.com \u4f86\u6e2c\u8a66\u60a8\u7684\u865b\u64ec\u4e3b\u6a5f\u662f\u5426\u914d\u7f6e\u6210\u529f\u3002\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u60a8\u61c9\u8a72\u80fd\u5920\u770b\u5230 \u201cWelcome to Example.com!\u201d \u7684\u9801\u9762\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-HYvdSRmZpY\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u4ee5\u4e0a\u6b65\u9a5f\uff0c\u60a8\u5df2\u6210\u529f\u5728 CentOS 7 \u4e0a\u914d\u7f6e\u4e86 httpd \u865b\u64ec\u4e3b\u6a5f\u3002\u9019\u4e0d\u50c5\u80fd\u5920\u5e6b\u52a9\u60a8\u66f4\u597d\u5730\u7ba1\u7406\u591a\u500b\u7db2\u7ad9\uff0c\u9084\u80fd\u63d0\u9ad8\u7db2\u7ad9\u7684\u6027\u80fd\u548c\u5b89\u5168\u6027\u3002\u5982\u679c\u60a8\u9700\u8981\u9032\u4e00\u6b65\u7684\u652f\u6301\u6216\u5c0b\u627e\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 CentOS 7 \u4e0a\u914d\u7f6e httpd \u865b\u64ec\u4e3b\u6a5f\uff0c\u5be6\u73fe\u591a\u7db2\u7ad9\u7ba1\u7406\uff0c\u63d0\u5347\u4f3a\u670d\u5668\u6548\u7387\u8207\u9748\u6d3b\u6027\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-43814","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43814","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=43814"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43814\/revisions"}],"predecessor-version":[{"id":43815,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43814\/revisions\/43815"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=43814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=43814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=43814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}