Skip to content
Open
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
17 changes: 16 additions & 1 deletion api/pages/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"embed"
"html/template"
"net/http"
"os"
"path/filepath"
"strings"

"github.com/0xJacky/Nginx-UI/settings"
Expand All @@ -13,6 +15,8 @@ import (
//go:embed *.tmpl
var tmplFS embed.FS

const maintenanceMountDir = "/etc/nginx/maintenance"

// MaintenancePageData maintenance page data structure
type MaintenancePageData struct {
Title string `json:"title"`
Expand Down Expand Up @@ -53,7 +57,18 @@ func MaintenancePage(c *gin.Context) {
return
}

// Parse template
// Try custom mounted HTML first (NGINX_UI_NGINX_MAINTENANCE_TEMPLATE)
if name := strings.TrimSpace(settings.NginxSettings.MaintenanceTemplate); name != "" {
name = filepath.Base(name)
full := filepath.Join(maintenanceMountDir, name)

if b, err := os.ReadFile(full); err == nil && len(b) > 0 {
c.Data(http.StatusServiceUnavailable, "text/html; charset=utf-8", b)
return
}
}

// Fallback: embedded template
tmpl, err := template.ParseFS(tmplFS, "maintenance.tmpl")
if err != nil {
c.String(http.StatusInternalServerError, "503 Service Unavailable")
Expand Down
1 change: 1 addition & 0 deletions app/src/api/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export interface NginxSettings {
restart_cmd: string
stub_status_port: number
container_name: string
maintenance_template?: string
}

export interface NginxLogSettings {
Expand Down
8 changes: 8 additions & 0 deletions app/src/views/preference/tabs/NginxSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ const { data } = storeToRefs(systemSettingsStore)
<AFormItem :label="$gettext('Stub Status Port')">
<AInputNumber v-model:value="data.nginx.stub_status_port" />
</AFormItem>
<AFormItem :label="$gettext('Maintenance template (filename only)')">
<AInput
v-model:value="data.nginx.maintenance_template"
:placeholder="$gettext('maintenance.html')" />
<div class="text-secondary mt-1">
{{$gettext('Mounted directory')}}: /etc/nginx/maintenance
</div>
</AFormItem>
<AFormItem :label="$gettext('Nginx Access Log Path')">
{{ data.nginx.access_log_path }}
</AFormItem>
Expand Down
1 change: 1 addition & 0 deletions settings/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Nginx struct {
RestartCmd string `json:"restart_cmd" protected:"true"`
StubStatusPort uint `json:"stub_status_port" binding:"omitempty,min=1,max=65535"`
ContainerName string `json:"container_name" protected:"true"`
MaintenanceTemplate string `json:"maintenance_template"`
}

var NginxSettings = &Nginx{}
Expand Down