国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

簡單粗暴的Caddy Server 使用介紹

2019-11-02 16:34:43
字體:
來源:轉載
供稿:網友

Caddy是一個Go寫的服務器軟件,官方的宣傳語“The HTTP/2 web server with automatic HTTPS”以及“Serve The Web Like It's 2016”簡明表達了這個軟件的優點和趨勢,它擁有基本的apache或者nginx有的web server模塊,同時還有一些很有特色的功能,比如:

HTTP/2

Automatic HTTPS

Multi-core

Websockets

Markdown

IPv6

Git

…...

用Caddy我們就可以很方便的部署一個Markdown文本作為靜態網站訪問,或者它的Git指令完成代碼的自動化部署,當然它很大的特色就是它的語法非常簡潔,比nginx還要簡單,配置部署起來很方便,下面隨便舉幾個例子吧。

對網站添加BasicAuth,用戶名ryan,密碼 12345

basicauth / ryan 12345

用CORS解決跨域問題

cors / {

    origin            http://allowedSite.com

    origin            http://anotherSite.org https://anotherSite.org

    methods           POST,PUT

    allow_credentials false

    max_age           3600

    allowed_headers   X-Custom-Header,X-Foobar

    exposed_headers   X-Something-Special,SomethingElse

}

IP過濾

ipfilter / {

    rule       block

    ip         212.10.15.0-255 213.10.15.0-10 5.23.4.24

    blockpage  /local/data/default.html

}

HTTPS 配置

tls ../cert.pem ../key.pem

實在太簡單了配置起來,具體還有其他簡潔到哭的指令可以看官方的User Guide,很快就刷完了。

既然Caddy自動部署https,而且是通過Let's Encrypt,那么就實踐一下,本博客是用Ghost 搭建,Nginx代理的,現在就改用Caddy,并支持https,步驟大體如下:

證書申請請移步 Let's Encrypt

Caddy 安裝很簡單,直接下載 https://caddyserver.com/docs/getting-started

配置Caddyfile,看起來指令簡潔明了

https://www.yuansir-web.com, http://www.yuansir-web.com, http://yuansir-web.com { redir https://yuansir-web.com{uri} tls yuansir88@gmail.com}https://yuansir-web.com { gzip errors {  log /var/log/caddy/yuansir-web.error.log {    size 50    age 30    keep 5  } } log /var/log/caddy/yuansir-web.access.log tls yuansir88@gmail.com proxy / http://127.0.0.1:2368 {  proxy_header X-Real-IP {remote}  proxy_header HOST {host}  proxy_header X-Forwarded-Proto {scheme} }}

用supservisor來管理Caddy運行

[program:caddy]command=/usr/bin/caddy -conf="/var/www/Caddyfile"directory=/var/www  ; directory to cwd to before exec (def no cwd)autostart=true    ; start at supervisord start (default: true)autorestart=unexpected  ; whether/when to restart (default: unexpected)startsecs=1     ; number of secs prog must stay running (def. 1)startretries=3    ; max # of serial start failures (default 3)exitcodes=0,2     ; 'expected' exit codes for process (default 0,2)stopsignal=QUIT    ; signal used to kill process (default TERM)stopwaitsecs=10    ; max num secs to wait b4 SIGKILL (default 10)stopasgroup=false    ; send stop signal to the UNIX process group (default false)user=www    ; setuid to this UNIX account to run the programredirect_stderr=true   ; redirect proc stderr to stdout (default false)stdout_logfile=/var/log/caddy.log  ; stdout log path, NONE for none; default AUTOstderr_logfile=/var/log/caddyerr.log  ; stderr log path, NONE for none; default AUTO
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 称多县| 星子县| 竹溪县| 南安市| 大同县| 花莲市| 黎城县| 金堂县| 疏勒县| 五峰| 会宁县| 横峰县| 岳普湖县| 米脂县| 潼南县| 嵊泗县| 门源| 罗江县| 博客| 鄂州市| 留坝县| 伊春市| 津市市| 富平县| 景东| 嘉黎县| 钟山县| 峨眉山市| 湖南省| 米易县| 潍坊市| 怀仁县| 杂多县| 探索| 安仁县| 军事| 乐平市| 南丰县| 平武县| 黄冈市| 肇源县|