diff --git a/debian/control b/debian/control index 3901c42..ae61f0b 100644 --- a/debian/control +++ b/debian/control @@ -8,6 +8,6 @@ X-Python3-Version: >= 3.7 Package: mainsail Architecture: any -Depends: ${misc:Pre-Depends} +Depends: ${misc:Pre-Depends}, nginx Description: Mainsail for Klipper ... diff --git a/debian/mainsail.install b/debian/mainsail.install index dd799a7..986a817 100755 --- a/debian/mainsail.install +++ b/debian/mainsail.install @@ -6,8 +6,13 @@ files=$(find \( -name . -o \ -name .git -prune -o \ -name .github -prune -o \ -name .gitignore -prune -o \ - -name debian -prune \) -o -print | sed -e 's/^\.\///') + -name debian -prune -o \ + -name nginx -prune \) -o -print | sed -e 's/^\.\///') for f in ${files}; do echo "${f} ${ROOT_PATH}/$(dirname ${f})" done + +echo "nginx/conf.d/* /etc/nginx/conf.d/" +echo "nginx/sites-available/mainsail /etc/nginx/sites-available/" +echo "nginx/sites-enabled/mainsail /etc/nginx/sites-enabled/" \ No newline at end of file diff --git a/debian/mainsail.postinst b/debian/mainsail.postinst new file mode 100644 index 0000000..03275a5 --- /dev/null +++ b/debian/mainsail.postinst @@ -0,0 +1,5 @@ +#!/bin/sh + +rm -f /etc/nginx/sites-enabled/default + +#DEBHELPER# diff --git a/nginx/conf.d/common_vars.conf b/nginx/conf.d/common_vars.conf new file mode 100644 index 0000000..09d2b03 --- /dev/null +++ b/nginx/conf.d/common_vars.conf @@ -0,0 +1,4 @@ +map $http_upgrade $connection_upgrade { + default upgrade; + '' close; +} \ No newline at end of file diff --git a/nginx/conf.d/upstream.conf b/nginx/conf.d/upstream.conf new file mode 100644 index 0000000..449ff99 --- /dev/null +++ b/nginx/conf.d/upstream.conf @@ -0,0 +1,4 @@ +upstream apiserver { + ip_hash; + server 127.0.0.1:7125; +} \ No newline at end of file diff --git a/nginx/sites-available/mainsail b/nginx/sites-available/mainsail new file mode 100644 index 0000000..8c65ff3 --- /dev/null +++ b/nginx/sites-available/mainsail @@ -0,0 +1,59 @@ +server { + listen 80 default_server; + # uncomment the next line to activate IPv6 + # listen [::]:80 default_server; + + 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 /usr/lib/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; + } +} \ No newline at end of file diff --git a/nginx/sites-enabled/mainsail b/nginx/sites-enabled/mainsail new file mode 120000 index 0000000..8d8f504 --- /dev/null +++ b/nginx/sites-enabled/mainsail @@ -0,0 +1 @@ +../sites-available/mainsail \ No newline at end of file