fix: update Dockerfile and init-nginx.sh for improved nginx control error handling

This commit is contained in:
Jacky 2025-05-03 07:45:50 +00:00
parent a4c11d521d
commit 855c3375f8
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
3 changed files with 59 additions and 7 deletions

View file

@ -32,8 +32,5 @@ RUN cp -rp /etc/nginx /etc/nginx.orig
# Set PATH to include Go installation and default go install binary location
ENV PATH="/usr/local/go/bin:/root/go/bin:${PATH}"
# Install air with go install (requires Go 1.23 or higher)
RUN go install github.com/air-verse/air@latest
# set zsh as default shell
RUN chsh -s $(which zsh)

View file

@ -1,3 +1,4 @@
#!/bin/bash
# init nginx config dir
if [ "$(ls -A /etc/nginx)" = "" ]; then
echo "Initialing Nginx config dir"
@ -5,5 +6,51 @@ if [ "$(ls -A /etc/nginx)" = "" ]; then
echo "Initialed Nginx config dir"
fi
src_dir="/usr/share/nginx/modules-available"
dest_dir="/etc/nginx/modules-enabled"
create_symlink() {
local module_name=$1
local weight=$2
local target="$dest_dir/$weight-$module_name"
local source="$src_dir/$module_name"
ln -sf "$source" "$target"
echo "Created symlink: $target -> $source"
}
modules=(
"mod-http-ndk.conf 10"
"mod-http-auth-pam.conf 50"
"mod-http-cache-purge.conf 50"
"mod-http-dav-ext.conf 50"
"mod-http-echo.conf 50"
"mod-http-fancyindex.conf 50"
"mod-http-geoip.conf 50"
"mod-http-geoip2.conf 50"
"mod-http-headers-more-filter.conf 50"
"mod-http-image-filter.conf 50"
"mod-http-lua.conf 50"
"mod-http-perl.conf 50"
"mod-http-subs-filter.conf 50"
"mod-http-uploadprogress.conf 50"
"mod-http-upstream-fair.conf 50"
"mod-http-xslt-filter.conf 50"
"mod-mail.conf 50"
"mod-nchan.conf 50"
"mod-stream.conf 50"
"mod-stream-geoip.conf 70"
"mod-stream-geoip2.conf 70"
)
for module in "${modules[@]}"; do
module_name=$(echo $module | awk '{print $1}')
weight=$(echo $module | awk '{print $2}')
create_symlink "$module_name" "$weight"
done
# start nginx
nginx

View file

@ -5,14 +5,16 @@ import (
"github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/gin-gonic/gin"
"github.com/uozi-tech/cosy"
)
// Reload reloads the nginx
func Reload(c *gin.Context) {
output, err := nginx.Reload()
if err != nil {
cosy.ErrHandler(c, err)
c.JSON(http.StatusInternalServerError, gin.H{
"message": output + err.Error(),
"level": nginx.GetLogLevel(output),
})
return
}
c.JSON(http.StatusOK, gin.H{
@ -25,7 +27,10 @@ func Reload(c *gin.Context) {
func TestConfig(c *gin.Context) {
output, err := nginx.TestConfig()
if err != nil {
cosy.ErrHandler(c, err)
c.JSON(http.StatusInternalServerError, gin.H{
"message": output + err.Error(),
"level": nginx.GetLogLevel(output),
})
return
}
c.JSON(http.StatusOK, gin.H{
@ -46,7 +51,10 @@ func Restart(c *gin.Context) {
func Status(c *gin.Context) {
lastOutput, err := nginx.GetLastOutput()
if err != nil {
cosy.ErrHandler(c, err)
c.JSON(http.StatusInternalServerError, gin.H{
"message": lastOutput + err.Error(),
"level": nginx.GetLogLevel(lastOutput),
})
return
}