Stefan Dej 8f11d50915 update docs
Signed-off-by: Stefan Dej <meteyou@gmail.com>
2020-11-28 02:31:38 +01:00

5.4 KiB

layout title parent nav_order permalink
default Mainsail Setup Guide 5 /setup/mainsail

Mainsail

Install webserver & reverse proxy (nginx)

nginx is important to mount all components on port 80 and host the static files from Mainsail. To install nginx you only need to execute:

sudo apt install nginx

now we create the config files with:

sudo touch /etc/nginx/sites-available/mainsail
sudo touch /etc/nginx/conf.d/upstreams.conf
sudo touch /etc/nginx/conf.d/common_vars.conf

Each file can be filled with the following content:

sudo nano /etc/nginx/conf.d/upstreams.conf

# /etc/nginx/conf.d/upstreams.conf

upstream apiserver {
    #edit your api port here
    ip_hash;
    server 127.0.0.1:7125;
}

upstream mjpgstreamer {
    #edit your webcam port here
    ip_hash;
    server 127.0.0.1:8081;
}

Save the file with CTRL+O and close the editor with CTRL+X.

sudo nano /etc/nginx/conf.d/common_vars.conf

# /etc/nginx/conf.d/common_vars.conf

map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}

Save the file with CTRL+O and close the editor with CTRL+X.

sudo nano /etc/nginx/sites-available/mainsail

# /etc/nginx/sites-available/mainsail

server {
    listen 80 default_server;
    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/x-javascript application/json application/xml;

    #web_path from mainsail static files
    root /home/pi/mainsail;

    index index.html;
    server_name _;

    #max upload size for gcodes
    client_max_body_size 200M;

    location / {
        try_files $uri $uri/ /index.html;
    }

    location /printer {
        proxy_pass http://apiserver/printer;
        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 /api {
        proxy_pass http://apiserver/api;
        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 /access {
        proxy_pass http://apiserver/access;
        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 /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 /machine {
        proxy_pass http://apiserver/machine;
        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 /server {
        proxy_pass http://apiserver/server;
        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/ {
        proxy_pass http://mjpgstreamer/;
    }
}

Save the file with CTRL+O and close the editor with CTRL+X.

Create directory for static files and active nginx config:

mkdir ~/mainsail
sudo rm /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/mainsail /etc/nginx/sites-enabled/
sudo service nginx restart

Now you can check again the API if it works with the reverse proxy. Open the url http:///printer/info in your browser. if you see a content like this:

{"result": {"hostname": "voron250", "error_detected": false, "version": "v0.8.0-479-gd586fb06", "is_ready": true, "message": "Printer is ready", "cpu": "4 core ARMv7 Processor rev 4 (v7l)"}}

Now we can install Mainsail (static httpdocs).

Install httpdocs

Now you can download the current mainsail static data

cd ~/mainsail
wget -q -O mainsail.zip https://github.com/meteyou/mainsail/releases/download/latest/mainsail.zip && unzip mainsail.zip && rm mainsail.zip

Now it should be possible to open the interface: http://<printer-ip>/.

Important macros

if you want to get the full experience with mainsail and klipper virtual_sdcard print, you should use these macros, or use them as templates for your own.

Macro Link{: .btn target="_blank"}

Change the Hostname (optional)

to use the hostname instate of the ip, you can install the avahi-daemon:

sudo apt install avahi-daemon

and you can config your hostname:

sudo raspi-config

in 2 Network Options > N1 Hostname you can edit your hostname of your raspberry pi. After a reboot you can use http://.local/ to open the webinterface.


< previous step{: .btn }