mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-14 11:04:29 +05:00
refactor(nginx.sh): refactor set_nginx_cfg()
- implements two dedicated nginx configs for mainsail and fluidd Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
# /etc/nginx/sites-available/<<UI>>
|
||||
# /etc/nginx/sites-available/fluidd
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
|
||||
access_log /var/log/nginx/<<UI>>-access.log;
|
||||
error_log /var/log/nginx/<<UI>>-error.log;
|
||||
access_log /var/log/nginx/fluidd-access.log;
|
||||
error_log /var/log/nginx/fluidd-error.log;
|
||||
|
||||
# disable this section on smaller hardware like a pi zero
|
||||
gzip on;
|
||||
@@ -16,8 +16,8 @@ server {
|
||||
gzip_http_version 1.1;
|
||||
gzip_types text/plain text/css text/xml text/javascript application/javascript application/x-javascript application/json application/xml;
|
||||
|
||||
# web_path from <<UI>> static files
|
||||
root /home/pi/<<UI>>;
|
||||
# web_path from fluidd static files
|
||||
root /home/pi/fluidd;
|
||||
|
||||
index index.html;
|
||||
server_name _;
|
||||
95
resources/mainsail
Normal file
95
resources/mainsail
Normal file
@@ -0,0 +1,95 @@
|
||||
# /etc/nginx/sites-available/mainsail
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
|
||||
access_log /var/log/nginx/mainsail-access.log;
|
||||
error_log /var/log/nginx/mainsail-error.log;
|
||||
|
||||
# disable this section on smaller hardware like a pi zero
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_proxied any;
|
||||
gzip_proxied expired no-cache no-store private auth;
|
||||
gzip_comp_level 4;
|
||||
gzip_buffers 16 8k;
|
||||
gzip_http_version 1.1;
|
||||
gzip_types text/plain text/css text/xml text/javascript application/javascript application/x-javascript application/json application/xml;
|
||||
|
||||
# web_path from mainsail static files
|
||||
root /home/pi/mainsail;
|
||||
|
||||
index index.html;
|
||||
server_name _;
|
||||
|
||||
# disable max upload size checks
|
||||
client_max_body_size 0;
|
||||
|
||||
# disable proxy request buffering
|
||||
proxy_request_buffering off;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location = /index.html {
|
||||
add_header Cache-Control "no-store, no-cache, must-revalidate";
|
||||
}
|
||||
|
||||
location /websocket {
|
||||
proxy_pass http://apiserver/websocket;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_read_timeout 86400;
|
||||
}
|
||||
|
||||
location ~ ^/(printer|api|access|machine|server)/ {
|
||||
proxy_pass http://apiserver$request_uri;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme $scheme;
|
||||
}
|
||||
|
||||
location /webcam/ {
|
||||
postpone_output 0;
|
||||
proxy_buffering off;
|
||||
proxy_ignore_headers X-Accel-Buffering;
|
||||
access_log off;
|
||||
error_log off;
|
||||
proxy_pass http://mjpgstreamer1/;
|
||||
}
|
||||
|
||||
location /webcam2/ {
|
||||
postpone_output 0;
|
||||
proxy_buffering off;
|
||||
proxy_ignore_headers X-Accel-Buffering;
|
||||
access_log off;
|
||||
error_log off;
|
||||
proxy_pass http://mjpgstreamer2/;
|
||||
}
|
||||
|
||||
location /webcam3/ {
|
||||
postpone_output 0;
|
||||
proxy_buffering off;
|
||||
proxy_ignore_headers X-Accel-Buffering;
|
||||
access_log off;
|
||||
error_log off;
|
||||
proxy_pass http://mjpgstreamer3/;
|
||||
}
|
||||
|
||||
location /webcam4/ {
|
||||
postpone_output 0;
|
||||
proxy_buffering off;
|
||||
proxy_ignore_headers X-Accel-Buffering;
|
||||
access_log off;
|
||||
error_log off;
|
||||
proxy_pass http://mjpgstreamer4/;
|
||||
}
|
||||
}
|
||||
@@ -269,34 +269,25 @@ function detect_conflicting_packages() {
|
||||
|
||||
function set_nginx_cfg() {
|
||||
local interface=${1}
|
||||
|
||||
if [[ ${SET_NGINX_CFG} == "true" ]]; then
|
||||
local cfg="${RESOURCES}/${interface}"
|
||||
#check for dependencies
|
||||
local dep=(nginx)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
status_msg "Creating Nginx configuration for ${interface^} ..."
|
||||
cat "${RESOURCES}/klipper_webui_nginx.cfg" > "${cfg}"
|
||||
sed -i "s/<<UI>>/${interface}/g" "${cfg}"
|
||||
local cfg_src="${RESOURCES}/${interface}"
|
||||
local cfg_dest="/etc/nginx/sites-available/${interface}"
|
||||
|
||||
status_msg "Creating NGINX configuration for ${interface^} ..."
|
||||
|
||||
# copy config to destination and set correct username
|
||||
[[ -f ${cfg_dest} ]] && sudo rm -f "${cfg_dest}"
|
||||
sudo cp "${cfg_src}" "${cfg_dest}"
|
||||
sudo sed -i "/root/s/pi/${USER}/" "${cfg_dest}"
|
||||
|
||||
if [[ ${SET_LISTEN_PORT} != "${DEFAULT_PORT}" ]]; then
|
||||
status_msg "Configuring port for ${interface^} ..."
|
||||
sed -i "s/listen\s[0-9]*;/listen ${SET_LISTEN_PORT};/" "${cfg}"
|
||||
sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${SET_LISTEN_PORT};/" "${cfg}"
|
||||
fi
|
||||
|
||||
#set correct user
|
||||
if [[ ${interface} == "mainsail" || ${interface} == "fluidd" ]]; then
|
||||
sudo sed -i "/root/s/pi/${USER}/" "${cfg}"
|
||||
fi
|
||||
|
||||
#moving the config file into correct directory
|
||||
sudo mv "${cfg}" "/etc/nginx/sites-available/${interface}"
|
||||
ok_msg "Nginx configuration for ${interface^} was set!"
|
||||
if [[ -n ${SET_LISTEN_PORT} ]]; then
|
||||
ok_msg "${interface^} configured for port ${SET_LISTEN_PORT}!"
|
||||
else
|
||||
ok_msg "${interface^} configured for default port ${DEFAULT_PORT}!"
|
||||
sudo sed -i "s/listen\s[0-9]*;/listen ${SET_LISTEN_PORT};/" "${cfg_dest}"
|
||||
sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${SET_LISTEN_PORT};/" "${cfg_dest}"
|
||||
fi
|
||||
|
||||
#remove nginx default config
|
||||
@@ -308,7 +299,16 @@ function set_nginx_cfg() {
|
||||
if [[ ! -e "/etc/nginx/sites-enabled/${interface}" ]]; then
|
||||
sudo ln -s "/etc/nginx/sites-available/${interface}" "/etc/nginx/sites-enabled/"
|
||||
fi
|
||||
|
||||
if [[ -n ${SET_LISTEN_PORT} ]]; then
|
||||
ok_msg "${interface^} configured for port ${SET_LISTEN_PORT}!"
|
||||
else
|
||||
ok_msg "${interface^} configured for default port ${DEFAULT_PORT}!"
|
||||
fi
|
||||
|
||||
sudo systemctl restart nginx.service
|
||||
|
||||
ok_msg "NGINX configuration for ${interface^} was set!"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user