{"id":43416,"date":"2024-10-05T16:11:28","date_gmt":"2024-10-05T08:11:28","guid":{"rendered":"https:\/\/server.hk\/cnblog\/43416\/"},"modified":"2024-10-05T16:11:28","modified_gmt":"2024-10-05T08:11:28","slug":"centos-8-%e9%83%a8%e7%bd%b2-caddy-web-%e4%bc%ba%e6%9c%8d%e5%99%a8%e5%85%b7%e9%ab%94%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/43416\/","title":{"rendered":"CentOS 8 \u90e8\u7f72 Caddy Web \u4f3a\u670d\u5668\u5177\u9ad4\u65b9\u6cd5"},"content":{"rendered":"<h1 id=\"centos-8-%e9%83%a8%e7%bd%b2-caddy-web-%e4%bc%ba%e6%9c%8d%e5%99%a8%e5%85%b7%e9%ab%94%e6%96%b9%e6%b3%95-ClKIRuYMqa\">CentOS 8 \u90e8\u7f72 Caddy Web \u4f3a\u670d\u5668\u5177\u9ad4\u65b9\u6cd5<\/h1>\n<p>Caddy \u662f\u4e00\u6b3e\u73fe\u4ee3\u5316\u7684\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u56e0\u5176\u7c21\u55ae\u6613\u7528\u548c\u81ea\u52d5\u5316 HTTPS \u914d\u7f6e\u800c\u53d7\u5230\u5ee3\u6cdb\u6b61\u8fce\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 CentOS 8 \u4e0a\u90e8\u7f72 Caddy Web \u4f3a\u670d\u5668\uff0c\u4e26\u63d0\u4f9b\u5177\u9ad4\u7684\u6b65\u9a5f\u548c\u793a\u4f8b\u3002<\/p>\n<h2 id=\"%e5%89%8d%e6%9c%9f%e6%ba%96%e5%82%99-ClKIRuYMqa\">\u524d\u671f\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u8acb\u78ba\u4fdd\u60a8\u5df2\u7d93\u64c1\u6709\u4e00\u500b\u904b\u884c CentOS 8 \u7684\u4f3a\u670d\u5668\uff0c\u4e26\u4e14\u64c1\u6709 root \u6b0a\u9650\u6216 sudo \u6b0a\u9650\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u4e00\u500b VPS \u670d\u52d9\u63d0\u4f9b\u5546\u4f86\u7372\u53d6\u9019\u6a23\u7684\u4f3a\u670d\u5668\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-caddy-ClKIRuYMqa\">\u5b89\u88dd Caddy<\/h2>\n<p>\u9996\u5148\uff0c\u6211\u5011\u9700\u8981\u5b89\u88dd Caddy\u3002Caddy \u63d0\u4f9b\u4e86\u5b98\u65b9\u7684\u5b89\u88dd\u8173\u672c\uff0c\u9019\u4f7f\u5f97\u5b89\u88dd\u904e\u7a0b\u8b8a\u5f97\u975e\u5e38\u7c21\u55ae\u3002\u8acb\u6309\u7167\u4ee5\u4e0b\u6b65\u9a5f\u9032\u884c\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo dnf install -y epel-release\nsudo dnf install -y https:\/\/dl.caddyserver.com\/download\/linux\/amd64\/caddy\n<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5 Caddy \u7684\u7248\u672c\uff1a<\/p>\n<pre><code>caddy version\n<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae-caddy-ClKIRuYMqa\">\u914d\u7f6e Caddy<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u914d\u7f6e Caddy\u3002Caddy \u7684\u914d\u7f6e\u6587\u4ef6\u901a\u5e38\u4f4d\u65bc \/etc\/caddy\/Caddyfile\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u60a8\u559c\u6b61\u7684\u6587\u672c\u7de8\u8f2f\u5668\u4f86\u7de8\u8f2f\u9019\u500b\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo nano \/etc\/caddy\/Caddyfile\n<\/code><\/pre>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u57fa\u672c\u7684 Caddyfile \u914d\u7f6e\u793a\u4f8b\uff1a<\/p>\n<pre><code>example.com {\n    root * \/var\/www\/html\n    file_server\n}\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u60a8\u9700\u8981\u5c07 <code>example.com<\/code> \u66ff\u63db\u70ba\u60a8\u7684\u57df\u540d\uff0c\u4e26\u78ba\u4fdd <code>\/var\/www\/html<\/code> \u76ee\u9304\u5b58\u5728\u4e26\u5305\u542b\u60a8\u7684\u7db2\u7ad9\u6587\u4ef6\u3002<\/p>\n<h2 id=\"%e5%95%9f%e5%8b%95-caddy-%e4%bc%ba%e6%9c%8d%e5%99%a8-ClKIRuYMqa\">\u555f\u52d5 Caddy \u4f3a\u670d\u5668<\/h2>\n<p>\u914d\u7f6e\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5 Caddy \u4f3a\u670d\u5668\uff1a<\/p>\n<pre><code>sudo systemctl start caddy\nsudo systemctl enable caddy\n<\/code><\/pre>\n<p>\u9019\u6a23\uff0cCaddy \u4f3a\u670d\u5668\u5c07\u5728\u7cfb\u7d71\u555f\u52d5\u6642\u81ea\u52d5\u555f\u52d5\u3002<\/p>\n<h2 id=\"%e6%aa%a2%e6%9f%a5-caddy-%e7%8b%80%e6%85%8b-ClKIRuYMqa\">\u6aa2\u67e5 Caddy \u72c0\u614b<\/h2>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5 Caddy \u7684\u904b\u884c\u72c0\u614b\uff1a<\/p>\n<pre><code>sudo systemctl status caddy\n<\/code><\/pre>\n<p>\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u60a8\u61c9\u8a72\u6703\u770b\u5230 Caddy \u6b63\u5728\u904b\u884c\u7684\u6d88\u606f\u3002<\/p>\n<h2 id=\"%e9%98%b2%e7%81%ab%e7%89%86%e8%a8%ad%e7%bd%ae-ClKIRuYMqa\">\u9632\u706b\u7246\u8a2d\u7f6e<\/h2>\n<p>\u5982\u679c\u60a8\u7684\u4f3a\u670d\u5668\u555f\u7528\u4e86\u9632\u706b\u7246\uff0c\u60a8\u9700\u8981\u78ba\u4fdd HTTP \u548c HTTPS \u6d41\u91cf\u88ab\u5141\u8a31\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u958b\u653e\u76f8\u61c9\u7684\u7aef\u53e3\uff1a<\/p>\n<pre><code>sudo firewall-cmd --permanent --add-service=http\nsudo firewall-cmd --permanent --add-service=https\nsudo firewall-cmd --reload\n<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-ClKIRuYMqa\">\u7e3d\u7d50<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u4ecb\u7d39\u4e86\u5982\u4f55\u5728 CentOS 8 \u4e0a\u90e8\u7f72 Caddy Web \u4f3a\u670d\u5668\u7684\u5177\u9ad4\u65b9\u6cd5\uff0c\u5305\u62ec\u5b89\u88dd\u3001\u914d\u7f6e\u548c\u555f\u52d5\u4f3a\u670d\u5668\u7684\u6b65\u9a5f\u3002Caddy \u7684\u81ea\u52d5 HTTPS \u529f\u80fd\u4f7f\u5f97\u7db2\u7ad9\u7684\u5b89\u5168\u6027\u5f97\u5230\u4e86\u4fdd\u969c\uff0c\u4e26\u4e14\u5176\u7c21\u55ae\u7684\u914d\u7f6e\u65b9\u5f0f\u4f7f\u5f97\u7ba1\u7406\u8b8a\u5f97\u66f4\u52a0\u65b9\u4fbf\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u9069\u5408\u5404\u7a2e\u9700\u6c42\u3002\u7121\u8ad6\u662f\u500b\u4eba\u7db2\u7ad9\u9084\u662f\u5546\u696d\u61c9\u7528\uff0c\u6211\u5011\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a> \u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u5728 CentOS 8 \u4e0a\u90e8\u7f72 Caddy Web \u4f3a\u670d\u5668\u7684\u5177\u9ad4\u65b9\u6cd5\uff0c\u7c21\u55ae\u6b65\u9a5f\u52a9\u60a8\u5feb\u901f\u642d\u5efa\u9ad8\u6548\u7db2\u7ad9\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-43416","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43416","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=43416"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43416\/revisions"}],"predecessor-version":[{"id":43417,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43416\/revisions\/43417"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=43416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=43416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=43416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}