dont use protocol for letsencrypt

This commit is contained in:
flufmonster 2018-07-04 19:33:26 +00:00 committed by root
parent f09fb9c78c
commit 75dd8ed58a
4 changed files with 17 additions and 11 deletions

View File

@ -172,12 +172,14 @@ func runWeb(ctx *cli.Context) error {
case setting.HTTP: case setting.HTTP:
err = runHTTP(listenAddr, context2.ClearHandler(m)) err = runHTTP(listenAddr, context2.ClearHandler(m))
case setting.HTTPS: case setting.HTTPS:
if setting.LetsEncrypt {
err = runLetsEncrypt(listenAddr, setting.Domain, setting.LetsEncryptDirectory, setting.LetsEncryptEmail, context2.ClearHandler(m))
break
}
if setting.RedirectOtherPort { if setting.RedirectOtherPort {
go runHTTPRedirector() go runHTTPRedirector()
} }
err = runHTTPS(listenAddr, setting.CertFile, setting.KeyFile, context2.ClearHandler(m)) err = runHTTPS(listenAddr, setting.CertFile, setting.KeyFile, context2.ClearHandler(m))
case setting.LetsEncrypt:
err = runLetsEncrypt(listenAddr, setting.Domain, setting.LetsEncryptDirectory, setting.LetsEncryptEmail, context2.ClearHandler(m))
case setting.FCGI: case setting.FCGI:
listener, err := net.Listen("tcp", listenAddr) listener, err := net.Listen("tcp", listenAddr)
if err != nil { if err != nil {

View File

@ -82,7 +82,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
## Server (`server`) ## Server (`server`)
- `PROTOCOL`: **http**: \[http, https, fcgi, unix, letsencrypt\] If using letsencrypt you must set `DOMAIN` to valid domain (ensure DNS is set and port 80 is accessible by letsencrypt validation server). - `PROTOCOL`: **http**: \[http, https, fcgi, unix\]
- `DOMAIN`: **localhost**: Domain name of this server. - `DOMAIN`: **localhost**: Domain name of this server.
- `ROOT_URL`: **%(PROTOCOL)s://%(DOMAIN)s:%(HTTP\_PORT)s/**: - `ROOT_URL`: **%(PROTOCOL)s://%(DOMAIN)s:%(HTTP\_PORT)s/**:
Overwrite the automatically generated public URL. Overwrite the automatically generated public URL.
@ -119,6 +119,8 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
- `REDIRECT_OTHER_PORT`: **false**: If true and `PROTOCOL` is https, redirects http requests - `REDIRECT_OTHER_PORT`: **false**: If true and `PROTOCOL` is https, redirects http requests
on another (https) port. on another (https) port.
- `PORT_TO_REDIRECT`: **80**: Port used when `REDIRECT_OTHER_PORT` is true. - `PORT_TO_REDIRECT`: **80**: Port used when `REDIRECT_OTHER_PORT` is true.
- `ENABLE_LETSENCRYPT`: **false**: If enabled you must set `DOMAIN` to valid domain (ensure DNS is set and port 80 is accessible by letsencrypt validation server).
By using Lets Encrypt you must consent to their [terms of service](https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf)
- `LETSENCRYPT_DIRECTORY`: **https**: Directory that Letsencrypt will use to cache information such as certs and private keys - `LETSENCRYPT_DIRECTORY`: **https**: Directory that Letsencrypt will use to cache information such as certs and private keys
- `LETSENCRYPT_EMAIL`: **email@example.com**: Email used by Letsencrypt to notify about problems with issued certificates. (No default) - `LETSENCRYPT_EMAIL`: **email@example.com**: Email used by Letsencrypt to notify about problems with issued certificates. (No default)

View File

@ -38,8 +38,9 @@ To learn more about the config values, please checkout the [Config Cheat Sheet](
```ini ```ini
[server] [server]
PROTOCOL=letsencrypt PROTOCOL=https
DOMAIN=git.example.com DOMAIN=git.example.com
ENABLE_LETSENCRYPT=true
LETSENCRYPT_DIRECTORY=https LETSENCRYPT_DIRECTORY=https
LETSENCRYPT_EMAIL=email@example.com LETSENCRYPT_EMAIL=email@example.com
``` ```

View File

@ -43,11 +43,10 @@ type Scheme string
// enumerates all the scheme types // enumerates all the scheme types
const ( const (
HTTP Scheme = "http" HTTP Scheme = "http"
HTTPS Scheme = "https" HTTPS Scheme = "https"
FCGI Scheme = "fcgi" FCGI Scheme = "fcgi"
UnixSocket Scheme = "unix" UnixSocket Scheme = "unix"
LetsEncrypt Scheme = "letsencrypt"
) )
// LandingPage describes the default page // LandingPage describes the default page
@ -106,6 +105,7 @@ var (
LandingPageURL LandingPage LandingPageURL LandingPage
UnixSocketPermission uint32 UnixSocketPermission uint32
EnablePprof bool EnablePprof bool
EnableLetsEncrypt bool
LetsEncryptDirectory string LetsEncryptDirectory string
LetsEncryptEmail string LetsEncryptEmail string
@ -714,8 +714,9 @@ func NewContext() {
log.Fatal(4, "Failed to parse unixSocketPermission: %s", UnixSocketPermissionRaw) log.Fatal(4, "Failed to parse unixSocketPermission: %s", UnixSocketPermissionRaw)
} }
UnixSocketPermission = uint32(UnixSocketPermissionParsed) UnixSocketPermission = uint32(UnixSocketPermissionParsed)
} else if sec.Key("PROTOCOL").String() == "letsencrypt" { }
Protocol = LetsEncrypt EnableLetsEncrypt := sec.Key("ENABLE_LETSENCRYPT").MustBool(false)
if EnableLetsEncrypt {
LetsEncryptDirectory = sec.Key("LETSENCRYPT_DIRECTORY").MustString("https") LetsEncryptDirectory = sec.Key("LETSENCRYPT_DIRECTORY").MustString("https")
LetsEncryptEmail = sec.Key("LETSENCRYPT_EMAIL").MustString("") LetsEncryptEmail = sec.Key("LETSENCRYPT_EMAIL").MustString("")
} }