mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-14 01:34:47 +08:00
feat: 创建静态、PHP 网站默认增加 404 页面 (#5498)
This commit is contained in:
parent
4c59090180
commit
f59bea27e8
@ -346,7 +346,8 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
|
||||
}
|
||||
|
||||
if len(create.FtpUser) != 0 && len(create.FtpPassword) != 0 {
|
||||
itemID, err := NewIFtpService().Create(dto.FtpCreate{User: create.FtpUser, Password: create.FtpPassword, Path: path.Join(global.CONF.System.BaseDir, "1panel/apps/openresty/openresty/www/sites", website.Alias, "index")})
|
||||
indexDir := path.Join(nginxInstall.GetPath(), "www", "sites", website.Alias, "index")
|
||||
itemID, err := NewIFtpService().Create(dto.FtpCreate{User: create.FtpUser, Password: create.FtpPassword, Path: indexDir})
|
||||
if err != nil {
|
||||
global.LOG.Errorf("create ftp for website failed, err: %v", err)
|
||||
}
|
||||
|
@ -80,18 +80,23 @@ func createIndexFile(website *model.Website, runtime *model.Runtime) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var (
|
||||
indexPath string
|
||||
indexContent string
|
||||
websiteService = NewIWebsiteService()
|
||||
indexFolder = path.Join(nginxInstall.GetPath(), "www", "sites", website.Alias, "index")
|
||||
)
|
||||
|
||||
indexFolder := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "www", "sites", website.Alias, "index")
|
||||
indexPath := ""
|
||||
indexContent := ""
|
||||
switch website.Type {
|
||||
case constant.Static:
|
||||
indexPath = path.Join(indexFolder, "index.html")
|
||||
indexContent = string(nginx_conf.Index)
|
||||
indexHtml, _ := websiteService.GetDefaultHtml("index")
|
||||
indexContent = indexHtml.Content
|
||||
case constant.Runtime:
|
||||
if runtime.Type == constant.RuntimePHP {
|
||||
indexPath = path.Join(indexFolder, "index.php")
|
||||
indexContent = string(nginx_conf.IndexPHP)
|
||||
indexPhp, _ := websiteService.GetDefaultHtml("php")
|
||||
indexContent = indexPhp.Content
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,6 +119,13 @@ func createIndexFile(website *model.Website, runtime *model.Runtime) error {
|
||||
if err := fileOp.WriteFile(indexPath, strings.NewReader(indexContent), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
html404, _ := websiteService.GetDefaultHtml("404")
|
||||
path404 := path.Join(indexFolder, "404.html")
|
||||
if err := fileOp.WriteFile(path404, strings.NewReader(html404.Content), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -245,12 +257,14 @@ func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain, a
|
||||
server.UpdateRootProxy([]string{proxy})
|
||||
case constant.Static:
|
||||
server.UpdateRoot(rootIndex)
|
||||
server.UpdateDirective("error_page", []string{"404", "/404.html"})
|
||||
case constant.Proxy:
|
||||
nginxInclude := fmt.Sprintf("/www/sites/%s/proxy/*.conf", website.Alias)
|
||||
server.UpdateDirective("include", []string{nginxInclude})
|
||||
case constant.Runtime:
|
||||
switch runtime.Type {
|
||||
case constant.RuntimePHP:
|
||||
server.UpdateDirective("error_page", []string{"404", "/404.html"})
|
||||
if runtime.Resource == constant.ResourceLocal {
|
||||
switch runtime.Type {
|
||||
case constant.RuntimePHP:
|
||||
|
@ -2039,8 +2039,9 @@ const message = {
|
||||
domain404: 'Website page does not exist',
|
||||
indexHtml: 'Static website default page',
|
||||
stopHtml: 'Website stop page',
|
||||
indePhp: 'PHP website default page',
|
||||
indexPHP: 'PHP website default page',
|
||||
sslExpireDate: 'Certificate expiration date',
|
||||
website404Helper: 'Website 404 error page only supports PHP runtime environment websites and static websites',
|
||||
},
|
||||
php: {
|
||||
short_open_tag: 'Short tag support',
|
||||
|
@ -1898,8 +1898,9 @@ const message = {
|
||||
domain404: '網站不存在頁面',
|
||||
indexHtml: '靜態網站預設頁',
|
||||
stopHtml: '網站停用頁',
|
||||
indePhp: 'PHP 網站預設頁',
|
||||
indexPHP: 'PHP 網站預設頁',
|
||||
sslExpireDate: '憑證過期時間',
|
||||
website404Helper: '網站 404 錯誤頁僅支援 PHP 運行環境網站和靜態網站',
|
||||
},
|
||||
php: {
|
||||
short_open_tag: '短標簽支持',
|
||||
|
@ -1900,8 +1900,9 @@ const message = {
|
||||
domain404: '网站不存在页',
|
||||
indexHtml: '静态网站默认页',
|
||||
stopHtml: '网站停用页',
|
||||
indePhp: 'PHP 网站默认页',
|
||||
indexPHP: 'PHP 网站默认页',
|
||||
sslExpireDate: '证书过期时间',
|
||||
website404Helper: '网站 404 错误页仅支持 PHP 运行环境网站和静态网站',
|
||||
},
|
||||
php: {
|
||||
short_open_tag: '短标签支持',
|
||||
|
@ -9,18 +9,22 @@
|
||||
<el-option :value="'404'" :label="$t('website.website404')"></el-option>
|
||||
<el-option :value="'domain404'" :label="$t('website.domain404')"></el-option>
|
||||
<el-option :value="'index'" :label="$t('website.indexHtml')"></el-option>
|
||||
<el-option :value="'php'" :label="$t('website.indePhp')"></el-option>
|
||||
<el-option :value="'php'" :label="$t('website.indexPHP')"></el-option>
|
||||
<el-option :value="'stop'" :label="$t('website.stopHtml')"></el-option>
|
||||
</el-select>
|
||||
<div class="mt-1.5">
|
||||
<el-text v-if="type == '404'" type="info">
|
||||
{{ $t('website.website404Helper') }}
|
||||
</el-text>
|
||||
</div>
|
||||
<div ref="htmlRef" class="default-html"></div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<template #footer>
|
||||
<span class="dialog-footer">
|
||||
<el-button @click="handleClose" :disabled="loading">{{ $t('commons.button.cancel') }}</el-button>
|
||||
<el-button type="primary" @click="submit()" :disabled="loading">
|
||||
{{ $t('commons.button.confirm') }}
|
||||
{{ $t('commons.button.save') }}
|
||||
</el-button>
|
||||
</span>
|
||||
</template>
|
||||
@ -89,7 +93,6 @@ const submit = async () => {
|
||||
const content = view.value.state.doc.toString();
|
||||
await UpdateDefaultHtml({ type: type.value, content: content });
|
||||
MsgSuccess(i18n.global.t('commons.msg.updateSuccess'));
|
||||
handleClose();
|
||||
} catch (error) {
|
||||
} finally {
|
||||
loading.value = false;
|
||||
@ -102,6 +105,6 @@ defineExpose({ acceptParams });
|
||||
.default-html {
|
||||
width: 100%;
|
||||
min-height: 300px;
|
||||
margin-top: 20px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
</style>
|
||||
|
Loading…
x
Reference in New Issue
Block a user