mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-12-18 21:38:57 +08:00
feat: Optimize HTTP to HTTPS redirection rules for non-443 port websites
This commit is contained in:
parent
d9579901fe
commit
917aa9b93d
4 changed files with 23 additions and 20 deletions
|
|
@ -742,6 +742,7 @@ func applySSL(website *model.Website, websiteSSL model.WebsiteSSL, req request.W
|
||||||
}
|
}
|
||||||
httpPorts := make(map[int]struct{})
|
httpPorts := make(map[int]struct{})
|
||||||
httpsPorts := make(map[int]struct{})
|
httpsPorts := make(map[int]struct{})
|
||||||
|
sslPort := 0
|
||||||
|
|
||||||
hasDefaultPort := false
|
hasDefaultPort := false
|
||||||
for _, domain := range domains {
|
for _, domain := range domains {
|
||||||
|
|
@ -769,6 +770,7 @@ func applySSL(website *model.Website, websiteSSL model.WebsiteSSL, req request.W
|
||||||
defaultHttpPortIPV6 := "[::]:" + defaultHttpPort
|
defaultHttpPortIPV6 := "[::]:" + defaultHttpPort
|
||||||
|
|
||||||
for port := range httpsPorts {
|
for port := range httpsPorts {
|
||||||
|
sslPort = port
|
||||||
portStr := strconv.Itoa(port)
|
portStr := strconv.Itoa(port)
|
||||||
server.RemoveListenByBind(portStr)
|
server.RemoveListenByBind(portStr)
|
||||||
server.RemoveListenByBind("[::]:" + portStr)
|
server.RemoveListenByBind("[::]:" + portStr)
|
||||||
|
|
@ -789,7 +791,7 @@ func applySSL(website *model.Website, websiteSSL model.WebsiteSSL, req request.W
|
||||||
server.UpdateListen(defaultHttpPortIPV6, website.DefaultServer)
|
server.UpdateListen(defaultHttpPortIPV6, website.DefaultServer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
server.AddHTTP2HTTPS()
|
server.AddHTTP2HTTPS(sslPort)
|
||||||
case constant.HTTPAlso:
|
case constant.HTTPAlso:
|
||||||
if hasDefaultPort {
|
if hasDefaultPort {
|
||||||
server.UpdateListen(defaultHttpPort, website.DefaultServer)
|
server.UpdateListen(defaultHttpPort, website.DefaultServer)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package components
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
|
|
@ -466,19 +467,27 @@ func (s *Server) RemoveListenByBind(bind string) {
|
||||||
s.Listens = listens
|
s.Listens = listens
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) AddHTTP2HTTPS() {
|
func (s *Server) AddHTTP2HTTPS(httpsPort int) {
|
||||||
newDir := Directive{
|
newDir := Directive{
|
||||||
Name: "if",
|
Name: "if",
|
||||||
Parameters: []string{"($scheme = http)"},
|
Parameters: []string{"($scheme = http)"},
|
||||||
Block: &Block{},
|
Block: &Block{},
|
||||||
}
|
}
|
||||||
block := &Block{}
|
block := &Block{}
|
||||||
block.AppendDirectives(&Directive{
|
if httpsPort == 443 {
|
||||||
Name: "return",
|
block.AppendDirectives(&Directive{
|
||||||
Parameters: []string{"301", "https://$host$request_uri"},
|
Name: "return",
|
||||||
})
|
Parameters: []string{"301", "https://$host$request_uri"},
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
block.AppendDirectives(&Directive{
|
||||||
|
Name: "return",
|
||||||
|
Parameters: []string{"301", fmt.Sprintf("https://$host$request_uri:%d", httpsPort)},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
newDir.Block = block
|
newDir.Block = block
|
||||||
s.UpdateDirectiveBySecondKey("if", "($scheme", newDir)
|
s.UpdateDirectiveBySecondKey("if", " ($scheme", newDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) UpdateAllowIPs(ips []string) {
|
func (s *Server) UpdateAllowIPs(ips []string) {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
:validate-on-rule-change="false"
|
:validate-on-rule-change="false"
|
||||||
v-loading="loading"
|
v-loading="loading"
|
||||||
>
|
>
|
||||||
<el-form-item :label="$t('commons.table.type')">
|
<el-form-item>
|
||||||
<el-radio-group v-model="website.type" @change="changeType">
|
<el-radio-group v-model="website.type" @change="changeType">
|
||||||
<el-radio-button v-for="item in WebsiteTypes" :key="item.value" :value="item.value">
|
<el-radio-button v-for="item in WebsiteTypes" :key="item.value" :value="item.value">
|
||||||
{{ item.label }}
|
{{ item.label }}
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,7 @@
|
||||||
:placeholder="index > 0 ? $t('website.domain') : ''"
|
:placeholder="index > 0 ? $t('website.domain') : ''"
|
||||||
@blur="handleDomainBlur(index)"
|
@blur="handleDomainBlur(index)"
|
||||||
></el-input>
|
></el-input>
|
||||||
<div
|
<span class="input-help" v-if="domainWarnings[index]">{{ $t('website.domainNotFQDN') }}</span>
|
||||||
v-if="domainWarnings[index]"
|
|
||||||
class="el-form-item__error"
|
|
||||||
style="position: relative; color: #e6a23c"
|
|
||||||
>
|
|
||||||
{{ $t('website.domainNotFQDN') }}
|
|
||||||
</div>
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="6">
|
<el-col :span="6">
|
||||||
|
|
@ -64,11 +58,9 @@
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
<div class="mt-1">
|
<el-button @click="openBatchDialog" type="primary" plain>
|
||||||
<el-button @click="openBatchDialog" type="primary" plain>
|
{{ $t('website.batchInput') }}
|
||||||
{{ $t('website.batchInput') }}
|
</el-button>
|
||||||
</el-button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<el-dialog v-model="batchDialogVisible" :title="$t('website.batchAdd')" width="600px">
|
<el-dialog v-model="batchDialogVisible" :title="$t('website.batchAdd')" width="600px">
|
||||||
<el-input
|
<el-input
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue