FCGI: Allow FCGI over unix sockets (#9298)
* FCGI: Allow FCGI over unix sockets * fixup! FCGI: Allow FCGI over unix sockets
This commit is contained in:
parent
4dc3993b22
commit
2c83dac5d4
5 changed files with 22 additions and 7 deletions
|
@ -122,6 +122,7 @@ func runWeb(ctx *cli.Context) error {
|
||||||
switch setting.Protocol {
|
switch setting.Protocol {
|
||||||
case setting.UnixSocket:
|
case setting.UnixSocket:
|
||||||
case setting.FCGI:
|
case setting.FCGI:
|
||||||
|
case setting.FCGIUnix:
|
||||||
default:
|
default:
|
||||||
// Save LOCAL_ROOT_URL if port changed
|
// Save LOCAL_ROOT_URL if port changed
|
||||||
cfg := ini.Empty()
|
cfg := ini.Empty()
|
||||||
|
@ -149,7 +150,7 @@ func runWeb(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
listenAddr := setting.HTTPAddr
|
listenAddr := setting.HTTPAddr
|
||||||
if setting.Protocol != setting.UnixSocket {
|
if setting.Protocol != setting.UnixSocket && setting.Protocol != setting.FCGIUnix {
|
||||||
listenAddr += ":" + setting.HTTPPort
|
listenAddr += ":" + setting.HTTPPort
|
||||||
}
|
}
|
||||||
log.Info("Listen: %v://%s%s", setting.Protocol, listenAddr, setting.AppSubURL)
|
log.Info("Listen: %v://%s%s", setting.Protocol, listenAddr, setting.AppSubURL)
|
||||||
|
@ -183,10 +184,13 @@ func runWeb(ctx *cli.Context) error {
|
||||||
err = runHTTPS("tcp", listenAddr, setting.CertFile, setting.KeyFile, context2.ClearHandler(m))
|
err = runHTTPS("tcp", listenAddr, setting.CertFile, setting.KeyFile, context2.ClearHandler(m))
|
||||||
case setting.FCGI:
|
case setting.FCGI:
|
||||||
NoHTTPRedirector()
|
NoHTTPRedirector()
|
||||||
err = runFCGI(listenAddr, context2.ClearHandler(m))
|
err = runFCGI("tcp", listenAddr, context2.ClearHandler(m))
|
||||||
case setting.UnixSocket:
|
case setting.UnixSocket:
|
||||||
NoHTTPRedirector()
|
NoHTTPRedirector()
|
||||||
err = runHTTP("unix", listenAddr, context2.ClearHandler(m))
|
err = runHTTP("unix", listenAddr, context2.ClearHandler(m))
|
||||||
|
case setting.FCGIUnix:
|
||||||
|
NoHTTPRedirector()
|
||||||
|
err = runFCGI("unix", listenAddr, context2.ClearHandler(m))
|
||||||
default:
|
default:
|
||||||
log.Fatal("Invalid protocol: %s", setting.Protocol)
|
log.Fatal("Invalid protocol: %s", setting.Protocol)
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,9 +37,9 @@ func NoMainListener() {
|
||||||
graceful.Manager.InformCleanup()
|
graceful.Manager.InformCleanup()
|
||||||
}
|
}
|
||||||
|
|
||||||
func runFCGI(listenAddr string, m http.Handler) error {
|
func runFCGI(network, listenAddr string, m http.Handler) error {
|
||||||
// This needs to handle stdin as fcgi point
|
// This needs to handle stdin as fcgi point
|
||||||
fcgiServer := graceful.NewServer("tcp", listenAddr)
|
fcgiServer := graceful.NewServer(network, listenAddr)
|
||||||
|
|
||||||
err := fcgiServer.ListenAndServe(func(listener net.Listener) error {
|
err := fcgiServer.ListenAndServe(func(listener net.Listener) error {
|
||||||
return fcgi.Serve(listener, m)
|
return fcgi.Serve(listener, m)
|
||||||
|
|
|
@ -140,7 +140,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
|
||||||
|
|
||||||
## Server (`server`)
|
## Server (`server`)
|
||||||
|
|
||||||
- `PROTOCOL`: **http**: \[http, https, fcgi, unix\]
|
- `PROTOCOL`: **http**: \[http, https, fcgi, unix, 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.
|
||||||
|
@ -155,7 +155,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
|
||||||
- `HTTP_ADDR`: **0.0.0.0**: HTTP listen address.
|
- `HTTP_ADDR`: **0.0.0.0**: HTTP listen address.
|
||||||
- If `PROTOCOL` is set to `fcgi`, Gitea will listen for FastCGI requests on TCP socket
|
- If `PROTOCOL` is set to `fcgi`, Gitea will listen for FastCGI requests on TCP socket
|
||||||
defined by `HTTP_ADDR` and `HTTP_PORT` configuration settings.
|
defined by `HTTP_ADDR` and `HTTP_PORT` configuration settings.
|
||||||
- If `PROTOCOL` is set to `unix`, this should be the name of the Unix socket file to use.
|
- If `PROTOCOL` is set to `unix` or `fcgi+unix`, this should be the name of the Unix socket file to use.
|
||||||
- `HTTP_PORT`: **3000**: HTTP listen port.
|
- `HTTP_PORT`: **3000**: HTTP listen port.
|
||||||
- If `PROTOCOL` is set to `fcgi`, Gitea will listen for FastCGI requests on TCP socket
|
- If `PROTOCOL` is set to `fcgi`, Gitea will listen for FastCGI requests on TCP socket
|
||||||
defined by `HTTP_ADDR` and `HTTP_PORT` configuration settings.
|
defined by `HTTP_ADDR` and `HTTP_PORT` configuration settings.
|
||||||
|
|
|
@ -42,6 +42,7 @@ const (
|
||||||
HTTP Scheme = "http"
|
HTTP Scheme = "http"
|
||||||
HTTPS Scheme = "https"
|
HTTPS Scheme = "https"
|
||||||
FCGI Scheme = "fcgi"
|
FCGI Scheme = "fcgi"
|
||||||
|
FCGIUnix Scheme = "fcgi+unix"
|
||||||
UnixSocket Scheme = "unix"
|
UnixSocket Scheme = "unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -553,6 +554,14 @@ func NewContext() {
|
||||||
KeyFile = sec.Key("KEY_FILE").String()
|
KeyFile = sec.Key("KEY_FILE").String()
|
||||||
case "fcgi":
|
case "fcgi":
|
||||||
Protocol = FCGI
|
Protocol = FCGI
|
||||||
|
case "fcgi+unix":
|
||||||
|
Protocol = FCGIUnix
|
||||||
|
UnixSocketPermissionRaw := sec.Key("UNIX_SOCKET_PERMISSION").MustString("666")
|
||||||
|
UnixSocketPermissionParsed, err := strconv.ParseUint(UnixSocketPermissionRaw, 8, 32)
|
||||||
|
if err != nil || UnixSocketPermissionParsed > 0777 {
|
||||||
|
log.Fatal("Failed to parse unixSocketPermission: %s", UnixSocketPermissionRaw)
|
||||||
|
}
|
||||||
|
UnixSocketPermission = uint32(UnixSocketPermissionParsed)
|
||||||
case "unix":
|
case "unix":
|
||||||
Protocol = UnixSocket
|
Protocol = UnixSocket
|
||||||
UnixSocketPermissionRaw := sec.Key("UNIX_SOCKET_PERMISSION").MustString("666")
|
UnixSocketPermissionRaw := sec.Key("UNIX_SOCKET_PERMISSION").MustString("666")
|
||||||
|
@ -607,6 +616,8 @@ func NewContext() {
|
||||||
defaultLocalURL = "http://unix/"
|
defaultLocalURL = "http://unix/"
|
||||||
case FCGI:
|
case FCGI:
|
||||||
defaultLocalURL = AppURL
|
defaultLocalURL = AppURL
|
||||||
|
case FCGIUnix:
|
||||||
|
defaultLocalURL = AppURL
|
||||||
default:
|
default:
|
||||||
defaultLocalURL = string(Protocol) + "://"
|
defaultLocalURL = string(Protocol) + "://"
|
||||||
if HTTPAddr == "0.0.0.0" {
|
if HTTPAddr == "0.0.0.0" {
|
||||||
|
|
|
@ -133,7 +133,7 @@ func NewMacaron() *macaron.Macaron {
|
||||||
if setting.EnableGzip {
|
if setting.EnableGzip {
|
||||||
m.Use(gzip.Middleware())
|
m.Use(gzip.Middleware())
|
||||||
}
|
}
|
||||||
if setting.Protocol == setting.FCGI {
|
if setting.Protocol == setting.FCGI || setting.Protocol == setting.FCGIUnix {
|
||||||
m.SetURLPrefix(setting.AppSubURL)
|
m.SetURLPrefix(setting.AppSubURL)
|
||||||
}
|
}
|
||||||
m.Use(public.Custom(
|
m.Use(public.Custom(
|
||||||
|
|
Reference in a new issue