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{
|
||||
Path: "./data",
|
||||
TemporaryFilePattern: "temp.*",
|
||||
},
|
||||
Accel: cacheproxy.Accel{
|
||||
ResponseWithHeaders: []string{"X-Sendfile", "X-Accel-Redirect"},
|
||||
Accel: cacheproxy.Accel{
|
||||
RespondWithHeaders: []string{"X-Sendfile", "X-Accel-Redirect"},
|
||||
},
|
||||
},
|
||||
},
|
||||
Misc: cacheproxy.MiscConfig{
|
||||
|
@ -36,17 +36,18 @@ func (upstream Upstream) GetPath(orig string) (string, bool, error) {
|
||||
type LocalStorage struct {
|
||||
Path string `yaml:"path"`
|
||||
TemporaryFilePattern string `yaml:"temporary-file-pattern"`
|
||||
|
||||
Accel Accel `yaml:"accel"`
|
||||
}
|
||||
|
||||
type Accel struct {
|
||||
EnableByHeader string `yaml:"enable-by-header"`
|
||||
ResponseWithHeaders []string `yaml:"response-with-headers"`
|
||||
EnableByHeader string `yaml:"enable-by-header"`
|
||||
RespondWithHeaders []string `yaml:"respond-with-headers"`
|
||||
}
|
||||
|
||||
type Storage struct {
|
||||
Type string `yaml:"type"`
|
||||
Local *LocalStorage `yaml:"local"`
|
||||
Accel Accel `yaml:"accel"`
|
||||
}
|
||||
|
||||
type CachePolicyOnPath struct {
|
||||
|
45
config.yaml
45
config.yaml
@ -88,21 +88,21 @@ upstream:
|
||||
allowed-redirect: "^https?://cf-builds.garudalinux.org/.*/chaotic-aur/.*$"
|
||||
|
||||
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
|
||||
# chunk-bytes: 1048576 # 1024*1024
|
||||
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
|
||||
|
||||
cache:
|
||||
timeout: 1h
|
||||
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
|
||||
- match: '^/.*-security/.*' # mostly ubuntu/debian security
|
||||
- match: '^/.*-security/.*' ## mostly ubuntu/debian security
|
||||
refresh-after: 1h
|
||||
- match: '^/archlinux-localaur/.*' # archlinux local repo
|
||||
- match: '^/archlinux-localaur/.*' ## archlinux local repo
|
||||
refresh-after: never
|
||||
- match: '^/(archlinux.*|chaotic-aur)/*.tar.*' # archlinux packages
|
||||
- match: '^/(archlinux.*|chaotic-aur)/*.tar.*' ## archlinux packages
|
||||
refresh-after: never
|
||||
- match: '/chaotic-aur/.*\.db$' # archlinux chaotic-aur database
|
||||
- match: '/chaotic-aur/.*\.db$' ## archlinux chaotic-aur database
|
||||
refresh-after: 24h
|
||||
- match: '/centos/7'
|
||||
refresh-after: never
|
||||
@ -110,20 +110,23 @@ cache:
|
||||
refresh-after: never
|
||||
|
||||
storage:
|
||||
type: local # ignored
|
||||
type: local ## ignored for now
|
||||
local:
|
||||
path: ./data # defaults to ./data
|
||||
path: ./data ## defaults to ./data
|
||||
|
||||
accel:
|
||||
# example nginx config:
|
||||
## location /i {
|
||||
## internal;
|
||||
## alias /path/to/data;
|
||||
## }
|
||||
## location / {
|
||||
## proxy_pass 127.0.0.1:8881;
|
||||
## proxy_set_header X-Accel-Path /i;
|
||||
## }
|
||||
##
|
||||
accel:
|
||||
## example nginx config:
|
||||
## location /i {
|
||||
## internal;
|
||||
## alias /path/to/data;
|
||||
## }
|
||||
## location / {
|
||||
## proxy_pass 127.0.0.1:8881;
|
||||
## 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) {
|
||||
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)
|
||||
if err != nil {
|
||||
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)
|
||||
|
||||
for _, headerKey := range server.Storage.Accel.ResponseWithHeaders {
|
||||
for _, headerKey := range server.Storage.Local.Accel.RespondWithHeaders {
|
||||
w.Header().Set(headerKey, accelPath)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user