mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 08:19:15 +08:00
feat: 增加静态网站
This commit is contained in:
parent
61d7e68262
commit
8099bcb031
@ -10,5 +10,6 @@ services:
|
|||||||
- ./log:/var/log/nginx
|
- ./log:/var/log/nginx
|
||||||
- ./conf/conf.d:/etc/nginx/conf.d/
|
- ./conf/conf.d:/etc/nginx/conf.d/
|
||||||
- ./ssl:/etc/nginx/ssl
|
- ./ssl:/etc/nginx/ssl
|
||||||
|
- ./www:/www/root/
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ type WebSiteCreate struct {
|
|||||||
Alias string `json:"alias" validate:"required"`
|
Alias string `json:"alias" validate:"required"`
|
||||||
Remark string `json:"remark"`
|
Remark string `json:"remark"`
|
||||||
OtherDomains string `json:"otherDomains"`
|
OtherDomains string `json:"otherDomains"`
|
||||||
AppType AppType `json:"appType" validate:"required"`
|
AppType AppType `json:"appType"`
|
||||||
AppInstall NewAppInstall `json:"appInstall"`
|
AppInstall NewAppInstall `json:"appInstall"`
|
||||||
AppID uint `json:"appID"`
|
AppID uint `json:"appID"`
|
||||||
AppInstallID uint `json:"appInstallID"`
|
AppInstallID uint `json:"appInstallID"`
|
||||||
|
@ -47,12 +47,18 @@ func (w WebsiteService) CreateWebsite(create dto.WebSiteCreate) error {
|
|||||||
Protocol: constant.ProtocolHTTP,
|
Protocol: constant.ProtocolHTTP,
|
||||||
}
|
}
|
||||||
|
|
||||||
if create.AppType == dto.NewApp {
|
if create.Type == "deployment" {
|
||||||
install, err := ServiceGroupApp.Install(create.AppInstall.Name, create.AppInstall.AppDetailId, create.AppInstall.Params)
|
if create.AppType == dto.NewApp {
|
||||||
if err != nil {
|
install, err := ServiceGroupApp.Install(create.AppInstall.Name, create.AppInstall.AppDetailId, create.AppInstall.Params)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
website.AppInstallID = install.ID
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := createStaticHtml(website); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
website.AppInstallID = install.ID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tx, ctx := getTxAndContext()
|
tx, ctx := getTxAndContext()
|
||||||
|
@ -43,6 +43,35 @@ func getDomain(domainStr string, websiteID uint) (model.WebSiteDomain, error) {
|
|||||||
return model.WebSiteDomain{}, nil
|
return model.WebSiteDomain{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createStaticHtml(website *model.WebSite) error {
|
||||||
|
nginxApp, err := appRepo.GetFirst(appRepo.WithKey("nginx"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
nginxInstall, err := appInstallRepo.GetFirst(appInstallRepo.WithAppId(nginxApp.ID))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
indexFolder := path.Join(constant.AppInstallDir, "nginx", nginxInstall.Name, "www", website.Alias)
|
||||||
|
indexPath := path.Join(indexFolder, "index.html")
|
||||||
|
indexContent := string(nginx_conf.Index)
|
||||||
|
fileOp := files.NewFileOp()
|
||||||
|
if !fileOp.Stat(indexFolder) {
|
||||||
|
if err := fileOp.CreateDir(indexFolder, 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !fileOp.Stat(indexPath) {
|
||||||
|
if err := fileOp.CreateFile(indexPath); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := fileOp.WriteFile(indexPath, strings.NewReader(indexContent), 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func configDefaultNginx(website *model.WebSite, domains []model.WebSiteDomain) error {
|
func configDefaultNginx(website *model.WebSite, domains []model.WebSiteDomain) error {
|
||||||
|
|
||||||
nginxApp, err := appRepo.GetFirst(appRepo.WithKey("nginx"))
|
nginxApp, err := appRepo.GetFirst(appRepo.WithKey("nginx"))
|
||||||
@ -53,14 +82,9 @@ func configDefaultNginx(website *model.WebSite, domains []model.WebSiteDomain) e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
appInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(website.AppInstallID))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
nginxFileName := website.Alias + ".conf"
|
nginxFileName := website.Alias + ".conf"
|
||||||
configPath := path.Join(constant.AppInstallDir, "nginx", nginxInstall.Name, "conf", "conf.d", nginxFileName)
|
configPath := path.Join(constant.AppInstallDir, "nginx", nginxInstall.Name, "conf", "conf.d", nginxFileName)
|
||||||
|
|
||||||
nginxContent := string(nginx_conf.WebsiteDefault)
|
nginxContent := string(nginx_conf.WebsiteDefault)
|
||||||
config := parser.NewStringParser(nginxContent).Parse()
|
config := parser.NewStringParser(nginxContent).Parse()
|
||||||
servers := config.FindServers()
|
servers := config.FindServers()
|
||||||
@ -74,8 +98,17 @@ func configDefaultNginx(website *model.WebSite, domains []model.WebSiteDomain) e
|
|||||||
server.UpdateListen(strconv.Itoa(domain.Port), false)
|
server.UpdateListen(strconv.Itoa(domain.Port), false)
|
||||||
}
|
}
|
||||||
server.UpdateServerName(serverNames)
|
server.UpdateServerName(serverNames)
|
||||||
proxy := fmt.Sprintf("http://127.0.0.1:%d", appInstall.HttpPort)
|
if website.Type == "deployment" {
|
||||||
server.UpdateRootProxy([]string{proxy})
|
appInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(website.AppInstallID))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
proxy := fmt.Sprintf("http://127.0.0.1:%d", appInstall.HttpPort)
|
||||||
|
server.UpdateRootProxy([]string{proxy})
|
||||||
|
} else {
|
||||||
|
server.UpdateRoot(path.Join("/www/root", website.Alias))
|
||||||
|
server.UpdateRootLocation()
|
||||||
|
}
|
||||||
|
|
||||||
config.FilePath = configPath
|
config.FilePath = configPath
|
||||||
if err := nginx.WriteConfig(config, nginx.IndentedStyle); err != nil {
|
if err := nginx.WriteConfig(config, nginx.IndentedStyle); err != nil {
|
||||||
|
@ -127,26 +127,41 @@ func (s *Server) UpdateServerName(names []string) {
|
|||||||
s.UpdateDirectives("server_name", serverNameDirective)
|
s.UpdateDirectives("server_name", serverNameDirective)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) UpdateRootProxy(proxy []string) {
|
func (s *Server) UpdateRoot(path string) {
|
||||||
//TODD 根据ID修改
|
rootDir := Directive{
|
||||||
dirs := s.FindDirectives("location")
|
Name: "root",
|
||||||
for _, dir := range dirs {
|
Parameters: []string{path},
|
||||||
location, ok := dir.(*Location)
|
|
||||||
if ok && location.Match == "/" {
|
|
||||||
newDir := Directive{
|
|
||||||
Name: "location",
|
|
||||||
Parameters: []string{"/"},
|
|
||||||
Block: &Block{},
|
|
||||||
}
|
|
||||||
block := &Block{}
|
|
||||||
block.Directives = append(block.Directives, &Directive{
|
|
||||||
Name: "proxy_pass",
|
|
||||||
Parameters: proxy,
|
|
||||||
})
|
|
||||||
newDir.Block = block
|
|
||||||
s.UpdateDirectiveBySecondKey("location", "/", newDir)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
s.UpdateDirectives("root", rootDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) UpdateRootLocation() {
|
||||||
|
newDir := Directive{
|
||||||
|
Name: "location",
|
||||||
|
Parameters: []string{"/"},
|
||||||
|
Block: &Block{},
|
||||||
|
}
|
||||||
|
block := &Block{}
|
||||||
|
block.Directives = append(block.Directives, &Directive{
|
||||||
|
Name: "root",
|
||||||
|
Parameters: []string{"index.html"},
|
||||||
|
})
|
||||||
|
newDir.Block = block
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) UpdateRootProxy(proxy []string) {
|
||||||
|
newDir := Directive{
|
||||||
|
Name: "location",
|
||||||
|
Parameters: []string{"/"},
|
||||||
|
Block: &Block{},
|
||||||
|
}
|
||||||
|
block := &Block{}
|
||||||
|
block.Directives = append(block.Directives, &Directive{
|
||||||
|
Name: "proxy_pass",
|
||||||
|
Parameters: proxy,
|
||||||
|
})
|
||||||
|
newDir.Block = block
|
||||||
|
s.UpdateDirectiveBySecondKey("location", "/", newDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) UpdateDirectiveBySecondKey(name string, key string, directive Directive) {
|
func (s *Server) UpdateDirectiveBySecondKey(name string, key string, directive Directive) {
|
||||||
|
34
cmd/server/nginx_conf/index.html
Normal file
34
cmd/server/nginx_conf/index.html
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>恭喜,站点创建成功!</title>
|
||||||
|
<style>
|
||||||
|
.container {
|
||||||
|
width: 60%;
|
||||||
|
margin: 10% auto 0;
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
padding: 2% 5%;
|
||||||
|
border-radius: 10px
|
||||||
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
padding-left: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul li {
|
||||||
|
line-height: 2.3
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #20a53a
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>恭喜, 站点创建成功!</h1>
|
||||||
|
<h3>这是默认index.html,本页面由系统自动生成</h3>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -15,3 +15,6 @@ var WebsiteDefault []byte
|
|||||||
|
|
||||||
//go:embed limit.conf
|
//go:embed limit.conf
|
||||||
var Limit []byte
|
var Limit []byte
|
||||||
|
|
||||||
|
//go:embed index.html
|
||||||
|
var Index []byte
|
||||||
|
@ -2,6 +2,8 @@ server {
|
|||||||
listen 80;
|
listen 80;
|
||||||
server_name ko.wp-1.com;
|
server_name ko.wp-1.com;
|
||||||
|
|
||||||
|
index index.php index.html index.htm default.php default.htm default.html;
|
||||||
|
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Host $server_name;
|
proxy_set_header X-Forwarded-Host $server_name;
|
||||||
@ -10,8 +12,5 @@ server {
|
|||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection "upgrade";
|
proxy_set_header Connection "upgrade";
|
||||||
|
|
||||||
location / {
|
|
||||||
proxy_pass http://127.0.0.1:8080;
|
|
||||||
}
|
|
||||||
access_log /var/log/nginx/nginx-log.log;
|
access_log /var/log/nginx/nginx-log.log;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-loading="loading">
|
<div v-loading="loading">
|
||||||
<el-row :gutter="20">
|
<el-row :gutter="5">
|
||||||
<el-col :span="12">
|
<el-col :span="12">
|
||||||
<el-input v-model="req.name" @blur="searchByName"></el-input>
|
<el-input v-model="req.name" @blur="searchByName"></el-input>
|
||||||
</el-col>
|
</el-col>
|
||||||
@ -12,7 +12,7 @@
|
|||||||
<el-col :span="1">
|
<el-col :span="1">
|
||||||
<el-button @click="sync">{{ $t('app.sync') }}</el-button>
|
<el-button @click="sync">{{ $t('app.sync') }}</el-button>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col v-for="(app, index) in apps" :key="index" :xs="8" :sm="8" :lg="4">
|
<el-col v-for="(app, index) in apps" :key="index" :span="6">
|
||||||
<div @click="getAppDetail(app.id)">
|
<div @click="getAppDetail(app.id)">
|
||||||
<el-card :body-style="{ padding: '0px' }" class="a-card">
|
<el-card :body-style="{ padding: '0px' }" class="a-card">
|
||||||
<el-row :gutter="24">
|
<el-row :gutter="24">
|
||||||
@ -123,13 +123,13 @@ onMounted(() => {
|
|||||||
padding: 5px;
|
padding: 5px;
|
||||||
|
|
||||||
.icon {
|
.icon {
|
||||||
width: 100%;
|
width: 95%;
|
||||||
height: 80%;
|
height: 80%;
|
||||||
padding: 10%;
|
padding: 10%;
|
||||||
margin-top: 5px;
|
margin-top: 5px;
|
||||||
.image {
|
.image {
|
||||||
width: auto;
|
width: 80%;
|
||||||
height: auto;
|
height: 80%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user