mainsail-crew / mainsail

Mainsail is the popular web interface for managing and controlling 3D printers with Klipper.
https://docs.mainsail.xyz
GNU General Public License v3.0
1.63k stars 342 forks source link

Password Required during manual install of Mainsail. #1891

Open ankonaskiff17 opened 1 month ago

ankonaskiff17 commented 1 month ago

Mainsail Version:

2.11.0

Browser:

Other (Please tell us below)

Device:

Other (Please tell us below)

Operating System:

Other (Please tell us below)

What happened?

While working my way through a manual install of Mainsail (NOT MainsailOS) on a RasPi running current version of Pi OS installed via the Pi Imager. When I got to what I will call the first check, prior to NGINX installation entered the command http://<printer-ip>:7125/server/info everything checked good in that I got the big block of information that was expected. The next step, Install web server & reverse proxy (NGINX) I worked my way through the process, mostly just copy/pasting the various lines and generating files using Nano. On the second check by entering http://<printer-ip>/server/info I got a 404 error on the web page. Went back through the whole NGINX process line by line in the event I had a typo or a Nano file didn;t get written. Everything was there and in the correct locations. The very last step sudo systemctl restart nginx I think is the problem because when I executed that restart nginx, I got this.

==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ==== Authentication is required to restart 'nginx.service'. Authenticating as: ,,, (pi) Password:

Once I entered my password, I got the below

==== AUTHENTICATION COMPLETE ==== I then entered http://<printer-ip>/server/info and got the big block of information that implies things are set up correctly.

What did you expect to happen instead?

I was not expecting a 404 error. Was hoping I got server info.

How to reproduce this bug?

I think if you just follow the process as written for a manual installation it should cause the same problem since there is no mechanism in a copy/paste process to accomodate password entry.

Instead of

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

Instead

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

And instruct user to then do single line because when I did the entire block I did not get any error or request for password

sudo systemctl restart nginx

Additional information:

I have noticed that PiOS is getting really tight with things requiring user Pi's password compared to past practice. It's been several months since I have messed with any Pi's and my memory is thinking that using sudo was good enough. In this instance I needed both sudo and my password.

dosubot[bot] commented 1 month ago

To address the 404 error during the manual installation of Mainsail on your Raspberry Pi, ensure your NGINX configuration is correctly set up and handle the authentication prompt effectively.

NGINX Configuration

  1. Verify Configuration: Ensure your NGINX configuration file (/etc/nginx/sites-available/mainsail) is correctly set up. Here is a sample configuration:

    server {
     listen 80;
    
     location / {
       root /usr/share/nginx/html;
       index index.html index.htm;
       try_files $uri $uri/ /index.html;
     }
    
     location /server/ {
       proxy_pass http://localhost:7125/;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;
     }
    
     include /etc/nginx/extra-conf.d/*.conf;
    }
  2. Place Mainsail Files: Ensure the Mainsail files are in the directory specified in the root directive (/usr/share/nginx/html).

  3. Enable Configuration: Create a symbolic link to enable the configuration:

    sudo ln -s /etc/nginx/sites-available/mainsail /etc/nginx/sites-enabled/

Handling Authentication Prompt

The authentication prompt when restarting NGINX is expected. Run the commands individually to handle the password prompt correctly:

  1. Create Mainsail Directory:

    mkdir ~/mainsail
  2. Remove Default NGINX Site:

    sudo rm /etc/nginx/sites-enabled/default
  3. Enable Mainsail Configuration:

    sudo ln -s /etc/nginx/sites-available/mainsail /etc/nginx/sites-enabled/
  4. Restart NGINX:

    sudo systemctl restart nginx

Verify the Setup

After completing these steps, verify the Mainsail backend server is running and accessible at localhost:7125:

curl http://localhost:7125/server/info

If the server info is correctly returned, you should be able to access it via http://<printer-ip>/server/info.

Additional Considerations

Following these steps should resolve the 404 error and handle the authentication prompt effectively. If you encounter further issues, please provide additional details for further assistance.

#### Details **Sources** - [.docker/nginx.conf](https://github.com/mainsail-crew/mainsail/blob/develop/.docker/nginx.conf) - [src/components/TheTopCornerMenu.vue](https://github.com/mainsail-crew/mainsail/blob/develop/src/components/TheTopCornerMenu.vue) - [src/store/gui/actions.ts](https://github.com/mainsail-crew/mainsail/blob/develop/src/store/gui/actions.ts)
**About Dosu** This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.