{"id":4196,"date":"2020-11-01T21:19:46","date_gmt":"2020-11-01T13:19:46","guid":{"rendered":"https:\/\/www.ookangzheng.com\/?p=4196"},"modified":"2020-11-05T02:20:14","modified_gmt":"2020-11-04T18:20:14","slug":"caddy-server-v2-setup","status":"publish","type":"post","link":"https:\/\/www.ookangzheng.com\/caddy-server-v2-setup\/","title":{"rendered":"Caddy server v2 setup"},"content":{"rendered":"\n
Debian 10 64bit with ssh<\/p>\n\n\n\n
Download url: https:\/\/caddyserver.com\/docs\/download<\/p>\n\n\n\n
sudo mv caddy \/usr\/bin\/<\/code><\/pre>\n\n\n\nStep 2: Create caddy user and group<\/h3>\n\n\n\n## Create caddy group\nsudo groupadd --system caddy\n\n## Create caddy user\nsudo useradd --system \\\n --gid caddy \\\n --create-home \\\n --home-dir \/var\/lib\/caddy \\\n --shell \/usr\/sbin\/nologin \\\n --comment \"Caddy web server\" \\\n caddy\n\n## Change permission to caddy exec file\n\nchown caddy:caddy \/usr\/bin\/caddy\nchmod +x \/usr\/bin\/caddy\n<\/code><\/pre>\n\n\n\nStep 3: Setup systemd service<\/h3>\n\n\n\n## Go to systemd dir\ncd \/etc\/systemd\/system\n\n## Download service file\nwget https:\/\/raw.githubusercontent.com\/caddyserver\/dist\/master\/init\/caddy.service\n\n## Enable and start\nsudo systemctl daemon-reload\nsudo systemctl enable caddy\nsudo systemctl start caddy\n\n## Stop caddy or reload\nsudo systemctl stop caddy\nsudo systemctl reload caddy<\/code><\/pre>\n\n\n\nStep 4: Check caddy system status and log<\/h3>\n\n\n\nsystemctl status caddy\njournalctl -u caddy\n<\/code><\/pre>\n\n\n\nStep 5: Setup config file for Caddy<\/h3>\n\n\n\ncd \/etc\/caddy\n\n## Config simple reverse proxy\n\nnano Caddyfile\n\n## Paste in this \n## Default https\n\nde11.xxx.com:91, de22.xxx.com:91 {\n reverse_proxy 127.0.0.1:300\n}<\/code><\/pre>\n\n\n\nAct as static file server<\/h3>\n\n\n\n## If you don't have an index file but you want to display a file listing, use the browse argument \n\nserver.com {\n\nencode zstd gzip\nroot * \/home\/me\/mysite\nfile_server browse\n\n}<\/code><\/pre>\n\n\n\nMatcher reverse proxy<\/h3>\n\n\n\n## In practice, we may want to use the reverse proxy only for API requests, i.e. requests with a base path of \/api\/. This is easy to do by adding a matcher token\n\nserver.com {\n\nfile_server\nreverse_proxy \/api\/* 127.0.0.1:9005\n\n}<\/code><\/pre>\n\n\n\nWork with env <\/h3>\n\n\n\nexport SITE_ADDRESS=localhost:9055\n\n## Caddy file config\n\n{$SITE_ADDRESS} {\nfile_server\n}<\/code><\/pre>\n\n\n\nWork with PHP-cgi<\/h3>\n\n\n\nexample.com\n\nroot * \/var\/www\nphp_fastcgi \/blog\/* localhost:9000\nfile_server<\/code><\/pre>\n\n\n\nRedirect www<\/code> to no www<\/code><\/h3>\n\n\n\nhttp:\/\/1234.xxx.xxx:91 {\n redir http:\/\/33.xxx.xxx:91{uri}\n}\n\nhttp:\/\/33.xxx.xxx:91 {\n reverse_proxy 127.0.0.1:30001\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"Caddy server download Debian 10 64bit with ssh Download url: https:\/\/caddyserver.com\/docs\/download Step 1: Move caddy file under \/usr\/bin Step 2:…<\/p>\n","protected":false},"author":1,"featured_media":4198,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37,32],"tags":[],"class_list":["post-4196","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-technology"],"_links":{"self":[{"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/posts\/4196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/comments?post=4196"}],"version-history":[{"count":0,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/posts\/4196\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/media\/4198"}],"wp:attachment":[{"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/media?parent=4196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/categories?post=4196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/tags?post=4196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}