mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-10 18:05:48 +02:00
fix: update Dockerfile and init-nginx.sh for improved nginx control error handling
This commit is contained in:
parent
a4c11d521d
commit
855c3375f8
3 changed files with 59 additions and 7 deletions
|
@ -32,8 +32,5 @@ RUN cp -rp /etc/nginx /etc/nginx.orig
|
||||||
# Set PATH to include Go installation and default go install binary location
|
# Set PATH to include Go installation and default go install binary location
|
||||||
ENV PATH="/usr/local/go/bin:/root/go/bin:${PATH}"
|
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
|
# set zsh as default shell
|
||||||
RUN chsh -s $(which zsh)
|
RUN chsh -s $(which zsh)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#!/bin/bash
|
||||||
# init nginx config dir
|
# init nginx config dir
|
||||||
if [ "$(ls -A /etc/nginx)" = "" ]; then
|
if [ "$(ls -A /etc/nginx)" = "" ]; then
|
||||||
echo "Initialing Nginx config dir"
|
echo "Initialing Nginx config dir"
|
||||||
|
@ -5,5 +6,51 @@ if [ "$(ls -A /etc/nginx)" = "" ]; then
|
||||||
echo "Initialed Nginx config dir"
|
echo "Initialed Nginx config dir"
|
||||||
fi
|
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
|
# start nginx
|
||||||
nginx
|
nginx
|
||||||
|
|
|
@ -5,14 +5,16 @@ import (
|
||||||
|
|
||||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/uozi-tech/cosy"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Reload reloads the nginx
|
// Reload reloads the nginx
|
||||||
func Reload(c *gin.Context) {
|
func Reload(c *gin.Context) {
|
||||||
output, err := nginx.Reload()
|
output, err := nginx.Reload()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cosy.ErrHandler(c, err)
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": output + err.Error(),
|
||||||
|
"level": nginx.GetLogLevel(output),
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
@ -25,7 +27,10 @@ func Reload(c *gin.Context) {
|
||||||
func TestConfig(c *gin.Context) {
|
func TestConfig(c *gin.Context) {
|
||||||
output, err := nginx.TestConfig()
|
output, err := nginx.TestConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cosy.ErrHandler(c, err)
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": output + err.Error(),
|
||||||
|
"level": nginx.GetLogLevel(output),
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
@ -46,7 +51,10 @@ func Restart(c *gin.Context) {
|
||||||
func Status(c *gin.Context) {
|
func Status(c *gin.Context) {
|
||||||
lastOutput, err := nginx.GetLastOutput()
|
lastOutput, err := nginx.GetLastOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cosy.ErrHandler(c, err)
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": lastOutput + err.Error(),
|
||||||
|
"level": nginx.GetLogLevel(lastOutput),
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue