Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions agent/cmd/server/nginx_conf/website_default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ server {

index index.php index.html index.htm default.php default.htm default.html;

proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";


access_log /www/sites/domain/log/access.log main;
error_log /www/sites/domain/log/error.log;

Expand Down
4 changes: 4 additions & 0 deletions agent/utils/nginx/components/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func (b *Block) FindDirectives(directiveName string) []IDirective {
return directives
}

func (b *Block) AppendDirectives(directives ...IDirective) {
b.Directives = append(b.Directives, directives...)
}

func (b *Block) UpdateDirective(key string, params []string) {
if key == "" || len(params) == 0 {
return
Expand Down
115 changes: 76 additions & 39 deletions agent/utils/nginx/components/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (s *Server) UpdateRootProxyForAi(proxy []string) {
Block: &Block{},
}
block := &Block{}
block.Directives = []IDirective{
block.AppendDirectives(
&Directive{
Name: "proxy_buffering",
Parameters: []string{
Expand Down Expand Up @@ -298,11 +298,12 @@ func (s *Server) UpdateRootProxyForAi(proxy []string) {
"off",
},
},
}
block.Directives = append(block.Directives, &Directive{
Name: "proxy_pass",
Parameters: proxy,
})
&Directive{
Name: "proxy_pass",
Parameters: proxy,
},
)

newDir.Block = block
s.UpdateDirectiveBySecondKey("location", "/", newDir)
}
Expand All @@ -314,7 +315,7 @@ func (s *Server) UpdateRootLocation() {
Block: &Block{},
}
block := &Block{}
block.Directives = append(block.Directives, &Directive{
block.AppendDirectives(&Directive{
Name: "root",
Parameters: []string{"index.html"},
})
Expand All @@ -328,10 +329,42 @@ func (s *Server) UpdateRootProxy(proxy []string) {
Block: &Block{},
}
block := &Block{}
block.Directives = append(block.Directives, &Directive{
Name: "proxy_pass",
Parameters: proxy,
})

block.AppendDirectives(
&Directive{
Name: "proxy_set_header",
Parameters: []string{"Host", "$host"},
},
&Directive{
Name: "proxy_set_header",
Parameters: []string{"X-Forwarded-For", "$proxy_add_x_forwarded_for"},
},
&Directive{
Name: "proxy_set_header",
Parameters: []string{"X-Forwarded-Host", "$server_name"},
},
&Directive{
Name: "proxy_set_header",
Parameters: []string{"X-Real-IP", "$remote_addr"},
},
&Directive{
Name: "proxy_set_header",
Parameters: []string{"Connection", "upgrade"},
},
&Directive{
Name: "proxy_set_header",
Parameters: []string{"Upgrade", "$http_upgrade"},
},
&Directive{
Name: "proxy_http_version",
Parameters: []string{"1.1"},
},
&Directive{
Name: "proxy_pass",
Parameters: proxy,
},
)

newDir.Block = block
s.UpdateDirectiveBySecondKey("location", "/", newDir)
}
Expand All @@ -343,20 +376,22 @@ func (s *Server) UpdatePHPProxy(proxy []string, localPath string) {
Block: &Block{},
}
block := &Block{}
block.Directives = append(block.Directives, &Directive{
Name: "fastcgi_pass",
Parameters: proxy,
})
block.Directives = append(block.Directives, &Directive{
Name: "include",
Parameters: []string{"fastcgi-php.conf"},
})
block.Directives = append(block.Directives, &Directive{
Name: "include",
Parameters: []string{"fastcgi_params"},
})
block.AppendDirectives(
&Directive{
Name: "fastcgi_pass",
Parameters: proxy,
},
&Directive{
Name: "include",
Parameters: []string{"fastcgi-php.conf"},
},
&Directive{
Name: "include",
Parameters: []string{"fastcgi_params"},
},
)
if localPath == "" {
block.Directives = append(block.Directives, &Directive{
block.AppendDirectives(&Directive{
Name: "set",
Parameters: []string{"$real_script_name", "$fastcgi_script_name"},
})
Expand All @@ -376,21 +411,23 @@ func (s *Server) UpdatePHPProxy(proxy []string, localPath string) {
},
},
}
block.Directives = append(block.Directives, ifDir)
block.Directives = append(block.Directives, &Directive{
Name: "fastcgi_param",
Parameters: []string{"SCRIPT_FILENAME", "$document_root$real_script_name"},
})
block.Directives = append(block.Directives, &Directive{
Name: "fastcgi_param",
Parameters: []string{"SCRIPT_NAME", "$real_script_name"},
})
block.Directives = append(block.Directives, &Directive{
Name: "fastcgi_param",
Parameters: []string{"PATH_INFO", "$path_info"},
})
block.AppendDirectives(
ifDir,
&Directive{
Name: "fastcgi_param",
Parameters: []string{"SCRIPT_FILENAME", "$document_root$real_script_name"},
},
&Directive{
Name: "fastcgi_param",
Parameters: []string{"SCRIPT_NAME", "$real_script_name"},
},
&Directive{
Name: "fastcgi_param",
Parameters: []string{"PATH_INFO", "$path_info"},
},
)
} else {
block.Directives = append(block.Directives, &Directive{
block.AppendDirectives(&Directive{
Name: "fastcgi_param",
Parameters: []string{"SCRIPT_FILENAME", localPath},
})
Expand Down Expand Up @@ -433,7 +470,7 @@ func (s *Server) AddHTTP2HTTPS() {
Block: &Block{},
}
block := &Block{}
block.Directives = append(block.Directives, &Directive{
block.AppendDirectives(&Directive{
Name: "return",
Parameters: []string{"301", "https://$host$request_uri"},
})
Expand Down
Loading