Caddy初探

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

Caddy
類似於Apache,Nginx,是一個高效能的HTTP和反向 Proxy伺服器

代碼
https://github.com/mholt/caddy

使用,先升級Go至1.9以上(https://my.oschina.net/u/2601...,然後

go get github.com/mholt/caddy/caddygo get github.com/caddyserver/buildscd $GOPATH/src/github.com/mholt/caddy/caddygo run build.go./caddy

初步嘗試,在caddy同目錄下建立Caddyfile檔案,並寫入配置,然後運行caddy

# cat Caddyfile0.0.0.0:2015pushbrowsewebsocket /echo catext    .htmllog    /var/log/access.logproxy  /api 127.0.0.1:7005header /api Access-Control-Allow-Origin *# # ./caddyActivating privacy features... done.http://0.0.0.0:2015

效果,運行了一個簡單的檔案伺服器

開啟https,需要加一行配置tls /root/ca.pem /root/ca-key.pem,

# cat Caddyfile0.0.0.0:2015 {    gzip    tls /etc/ssl/caddy/ca.pem /etc/ssl/caddy/ca-key.pem    #tls xxxx@qq.com {    #    protocols tls1.0 tls1.2    #}    push    browse    websocket /echo cat    ext    .html    log    /var/log/access.log    proxy  /api 127.0.0.1:7005    header /api Access-Control-Allow-Origin *}# ./caddyActivating privacy features... done.https://0.0.0.0:2015

看到有很多文章說Caddy可以自動申請認證,但我嘗試了多次都沒有成功。牆外的虛機也不行……

反向 Proxy,簡單配置如下,給原來的web服務直接加了https,挺好。

0.0.0.0:2015 {    gzip    tls /root/ca.pem /root/ca-key.pem    proxy / http://localhost:8080 {        header_upstream Host {host}        header_upstream X-Real-IP {remote}        header_upstream X-Forwarded-For {remote}        header_upstream X-Forwarded-Proto {scheme}    }  } 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.