move x-accel into local storage configuration
This commit is contained in:
parent
504a809c16
commit
83dfcba4ae
@ -55,9 +55,9 @@ func configFromFile(path string) (*cacheproxy.Config, error) {
|
|||||||
Local: &cacheproxy.LocalStorage{
|
Local: &cacheproxy.LocalStorage{
|
||||||
Path: "./data",
|
Path: "./data",
|
||||||
TemporaryFilePattern: "temp.*",
|
TemporaryFilePattern: "temp.*",
|
||||||
},
|
Accel: cacheproxy.Accel{
|
||||||
Accel: cacheproxy.Accel{
|
RespondWithHeaders: []string{"X-Sendfile", "X-Accel-Redirect"},
|
||||||
ResponseWithHeaders: []string{"X-Sendfile", "X-Accel-Redirect"},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Misc: cacheproxy.MiscConfig{
|
Misc: cacheproxy.MiscConfig{
|
||||||
|
@ -36,17 +36,18 @@ func (upstream Upstream) GetPath(orig string) (string, bool, error) {
|
|||||||
type LocalStorage struct {
|
type LocalStorage struct {
|
||||||
Path string `yaml:"path"`
|
Path string `yaml:"path"`
|
||||||
TemporaryFilePattern string `yaml:"temporary-file-pattern"`
|
TemporaryFilePattern string `yaml:"temporary-file-pattern"`
|
||||||
|
|
||||||
|
Accel Accel `yaml:"accel"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Accel struct {
|
type Accel struct {
|
||||||
EnableByHeader string `yaml:"enable-by-header"`
|
EnableByHeader string `yaml:"enable-by-header"`
|
||||||
ResponseWithHeaders []string `yaml:"response-with-headers"`
|
RespondWithHeaders []string `yaml:"respond-with-headers"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
Type string `yaml:"type"`
|
Type string `yaml:"type"`
|
||||||
Local *LocalStorage `yaml:"local"`
|
Local *LocalStorage `yaml:"local"`
|
||||||
Accel Accel `yaml:"accel"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type CachePolicyOnPath struct {
|
type CachePolicyOnPath struct {
|
||||||
|
45
config.yaml
45
config.yaml
@ -88,21 +88,21 @@ upstream:
|
|||||||
allowed-redirect: "^https?://cf-builds.garudalinux.org/.*/chaotic-aur/.*$"
|
allowed-redirect: "^https?://cf-builds.garudalinux.org/.*/chaotic-aur/.*$"
|
||||||
|
|
||||||
misc:
|
misc:
|
||||||
first-chunk-bytes: 31457280 # 1024*1024*30, all upstreams with 200 response will wait for the first chunks to select a upstream by bandwidth, instead of by latency. defaults to 50M
|
first-chunk-bytes: 31457280 ## 1024*1024*30, all upstreams with 200 response will wait for the first chunks to select a upstream by bandwidth, instead of by latency. defaults to 50M
|
||||||
# chunk-bytes: 1048576 # 1024*1024
|
# chunk-bytes: 1048576 ## 1024*1024
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
timeout: 1h
|
timeout: 1h
|
||||||
policies:
|
policies:
|
||||||
- match: '.*\.(rpm|deb|apk|iso)$' # rpm/deb/apk/iso won't change, create only
|
- match: '.*\.(rpm|deb|apk|iso)$' ## rpm/deb/apk/iso won't change, create only
|
||||||
refresh-after: never
|
refresh-after: never
|
||||||
- match: '^/.*-security/.*' # mostly ubuntu/debian security
|
- match: '^/.*-security/.*' ## mostly ubuntu/debian security
|
||||||
refresh-after: 1h
|
refresh-after: 1h
|
||||||
- match: '^/archlinux-localaur/.*' # archlinux local repo
|
- match: '^/archlinux-localaur/.*' ## archlinux local repo
|
||||||
refresh-after: never
|
refresh-after: never
|
||||||
- match: '^/(archlinux.*|chaotic-aur)/*.tar.*' # archlinux packages
|
- match: '^/(archlinux.*|chaotic-aur)/*.tar.*' ## archlinux packages
|
||||||
refresh-after: never
|
refresh-after: never
|
||||||
- match: '/chaotic-aur/.*\.db$' # archlinux chaotic-aur database
|
- match: '/chaotic-aur/.*\.db$' ## archlinux chaotic-aur database
|
||||||
refresh-after: 24h
|
refresh-after: 24h
|
||||||
- match: '/centos/7'
|
- match: '/centos/7'
|
||||||
refresh-after: never
|
refresh-after: never
|
||||||
@ -110,20 +110,23 @@ cache:
|
|||||||
refresh-after: never
|
refresh-after: never
|
||||||
|
|
||||||
storage:
|
storage:
|
||||||
type: local # ignored
|
type: local ## ignored for now
|
||||||
local:
|
local:
|
||||||
path: ./data # defaults to ./data
|
path: ./data ## defaults to ./data
|
||||||
|
|
||||||
accel:
|
accel:
|
||||||
# example nginx config:
|
## example nginx config:
|
||||||
## location /i {
|
## location /i {
|
||||||
## internal;
|
## internal;
|
||||||
## alias /path/to/data;
|
## alias /path/to/data;
|
||||||
## }
|
## }
|
||||||
## location / {
|
## location / {
|
||||||
## proxy_pass 127.0.0.1:8881;
|
## proxy_pass 127.0.0.1:8881;
|
||||||
## proxy_set_header X-Accel-Path /i;
|
## proxy_set_header X-Accel-Path /i;
|
||||||
## }
|
## }
|
||||||
##
|
##
|
||||||
|
## then cache proxy will respond to backend a header to indicate sendfile(join(X-Accel-Path, relpath))
|
||||||
|
# enable-by-header: "X-Accel-Path"
|
||||||
|
|
||||||
# enable-by-header: "X-Accel-Path"
|
## respond with different headers to
|
||||||
|
# respond-with-headers: [X-Sendfile, X-Accel-Redirect]
|
||||||
|
@ -107,7 +107,7 @@ type Chunk struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) serveFile(w http.ResponseWriter, r *http.Request, path string) {
|
func (server *Server) serveFile(w http.ResponseWriter, r *http.Request, path string) {
|
||||||
if location := r.Header.Get(server.Storage.Accel.EnableByHeader); server.Storage.Accel.EnableByHeader != "" && location != "" {
|
if location := r.Header.Get(server.Storage.Local.Accel.EnableByHeader); server.Storage.Local.Accel.EnableByHeader != "" && location != "" {
|
||||||
relPath, err := filepath.Rel(server.Storage.Local.Path, path)
|
relPath, err := filepath.Rel(server.Storage.Local.Path, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
@ -115,7 +115,7 @@ func (server *Server) serveFile(w http.ResponseWriter, r *http.Request, path str
|
|||||||
}
|
}
|
||||||
accelPath := filepath.Join(location, relPath)
|
accelPath := filepath.Join(location, relPath)
|
||||||
|
|
||||||
for _, headerKey := range server.Storage.Accel.ResponseWithHeaders {
|
for _, headerKey := range server.Storage.Local.Accel.RespondWithHeaders {
|
||||||
w.Header().Set(headerKey, accelPath)
|
w.Header().Set(headerKey, accelPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user