mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-13 18:44:29 +05:00
add octoprint reverse proxy
This commit is contained in:
40
resources/octoprint_nginx.cfg
Normal file
40
resources/octoprint_nginx.cfg
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
map $http_upgrade $connection_upgrade {
|
||||||
|
default upgrade;
|
||||||
|
'' close;
|
||||||
|
}
|
||||||
|
|
||||||
|
upstream octoprint {
|
||||||
|
server 127.0.0.1:5000;
|
||||||
|
}
|
||||||
|
|
||||||
|
upstream mjpg-streamer {
|
||||||
|
server 127.0.0.1:8080;
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
listen [::]:80;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://octoprint/;
|
||||||
|
proxy_set_header Host $http_host;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
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;
|
||||||
|
#proxy_set_header X-Script-Name /;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
client_max_body_size 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /webcam {
|
||||||
|
proxy_pass http://mjpg-streamer/;
|
||||||
|
}
|
||||||
|
|
||||||
|
# redirect server error pages to the static page /50x.html
|
||||||
|
error_page 500 502 503 504 /50x.html;
|
||||||
|
location = /50x.html {
|
||||||
|
root html;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -78,6 +78,13 @@ restart_octoprint(){
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
restart_nginx(){
|
||||||
|
if [ -e /etc/init.d/nginx ]; then
|
||||||
|
status_msg "Restarting Nginx Service ..."
|
||||||
|
sudo /etc/init.d/nginx restart && sleep 2 && ok_msg "Nginx Service restarted!"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
dep_check(){
|
dep_check(){
|
||||||
for package in "${dep[@]}"
|
for package in "${dep[@]}"
|
||||||
do
|
do
|
||||||
@@ -261,12 +268,10 @@ create_custom_hostname(){
|
|||||||
top_border
|
top_border
|
||||||
echo -e "| You can change the hostname of this machine to use |"
|
echo -e "| You can change the hostname of this machine to use |"
|
||||||
echo -e "| that name to open the Interface in your browser. |"
|
echo -e "| that name to open the Interface in your browser. |"
|
||||||
echo -e "| This option is completely optional and can also be |"
|
|
||||||
echo -e "| done at a later point in time if you are unsure. |"
|
|
||||||
echo -e "| |"
|
echo -e "| |"
|
||||||
echo -e "| Example: If you set the hostname to 'my-printer' |"
|
echo -e "| Example: If you set the hostname to 'my-printer' |"
|
||||||
echo -e "| you can open Mainsail by browsing to: |"
|
echo -e "| you can open Mainsail/Octoprint by |"
|
||||||
echo -e "| http://my-printer.local |"
|
echo -e "| browsing to: http://my-printer.local |"
|
||||||
bottom_border
|
bottom_border
|
||||||
while true; do
|
while true; do
|
||||||
echo -e "${cyan}"
|
echo -e "${cyan}"
|
||||||
@@ -323,7 +328,7 @@ set_hostname(){
|
|||||||
echo "127.0.0.1 $NEW_HOSTNAME ###set by kiauh" | sudo tee -a /etc/hosts &>/dev/null
|
echo "127.0.0.1 $NEW_HOSTNAME ###set by kiauh" | sudo tee -a /etc/hosts &>/dev/null
|
||||||
fi
|
fi
|
||||||
ok_msg "New hostname successfully configured!"
|
ok_msg "New hostname successfully configured!"
|
||||||
ok_msg "You need to reboot your machine for changes to take effect!"
|
ok_msg "Remember to reboot your machine for the changes to take effect!"
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
warn_msg "'$NEW_HOSTNAME' is not a valid hostname!"
|
warn_msg "'$NEW_HOSTNAME' is not a valid hostname!"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ octoprint_install_routine(){
|
|||||||
add_groups
|
add_groups
|
||||||
configure_autostart
|
configure_autostart
|
||||||
add_reboot_permission
|
add_reboot_permission
|
||||||
|
octoprint_reverse_proxy_dialog
|
||||||
load_server
|
load_server
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,6 +109,41 @@ add_reboot_permission(){
|
|||||||
sleep 2
|
sleep 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
octoprint_reverse_proxy_dialog(){
|
||||||
|
top_border
|
||||||
|
echo -e "| If you want to have nicer URLs or simply need | "
|
||||||
|
echo -e "| OctoPrint to run on port 80 (http's default port) | "
|
||||||
|
echo -e "| due to some network restrictions, you can set up a | "
|
||||||
|
echo -e "| reverse proxy instead of configuring OctoPrint to | "
|
||||||
|
echo -e "| run on port 80. | "
|
||||||
|
bottom_border
|
||||||
|
while true; do
|
||||||
|
echo -e "${cyan}"
|
||||||
|
read -p "###### Do you want to set up a reverse proxy now? (Y/n): " yn
|
||||||
|
echo -e "${default}"
|
||||||
|
case "$yn" in
|
||||||
|
Y|y|Yes|yes|"") octoprint_reverse_proxy; break;;
|
||||||
|
N|n|No|no) break;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
octoprint_reverse_proxy(){
|
||||||
|
if ! [[ $(dpkg-query -f'${Status}' --show nginx 2>/dev/null) = *\ installed ]]; then
|
||||||
|
sudo apt-get install nginx -y
|
||||||
|
fi
|
||||||
|
cat ${HOME}/kiauh/resources/octoprint_nginx.cfg > ${HOME}/kiauh/resources/octoprint
|
||||||
|
sudo mv ${HOME}/kiauh/resources/octoprint /etc/nginx/sites-available/octoprint
|
||||||
|
if [ -e /etc/nginx/sites-enabled/default ]; then
|
||||||
|
sudo rm /etc/nginx/sites-enabled/default
|
||||||
|
fi
|
||||||
|
if [ ! -e /etc/nginx/sites-enabled/octoprint ]; then
|
||||||
|
sudo ln -s /etc/nginx/sites-available/octoprint /etc/nginx/sites-enabled/
|
||||||
|
fi
|
||||||
|
restart_nginx
|
||||||
|
create_custom_hostname
|
||||||
|
}
|
||||||
|
|
||||||
load_server(){
|
load_server(){
|
||||||
start_octoprint
|
start_octoprint
|
||||||
#create an octoprint.log symlink in home-dir just for convenience
|
#create an octoprint.log symlink in home-dir just for convenience
|
||||||
|
|||||||
Reference in New Issue
Block a user