Rock the Lovely Pluto.jl Notebook in the LXD-LXC Cloud behind Nginx

1. Background

  • A private cloud based on the powerful LXD-LXC system container technology
  • Nginx as the frontend to support both HTTP and HTTPS
  • Ubuntun or Arch Linux-based containers

2. Install Julia onto your container and configure your .bashrc or .zshrc

lxc file push ~/julia-1.9.4-linux-x86_64.tar.gz u2204-01/home/ubuntu/
lxc exec u2204-01 -- su - ubuntu --login
sudo tar -xzf ./julia-1.9.4-linux-x86_64.tar.gz -C /opt/
  • vim ~/.zshrc
export JULIA_HOME="/opt/julia-1.9.4"
export JULIA_PKG_SERVER="https://mirrors.pku.edu.cn/julia"
PATH+=":$JULIA_HOME/bin"
  • source ~/.zshrc

3. Install Pluto (Easy. Omitted.)

4. Install tmux to manage a Pluto session in the container

sudo apt-get install tmux (Ubuntu)
sudo pacman -S tmux (Arch Linux)

5. Create a new tmux session and run Pluto

  • I set both the require_secret_for_open_links and require_secret_for_access flags to false, Choose what you like.
tmux new -s mypluto

julia> import Pluto; Pluto.run(;host="0.0.0.0", port=1234, launch_browser=false, require_secret_for_open_links=false, require_secret_for_access=false)
[ Info: Loading...
β”Œ Info:
β”” Go to http://0.0.0.0:1234/ in your browser to start writing ~ have fun!
β”Œ Info:
β”‚ Press Ctrl+C in this terminal to stop Pluto
β””
  • Exit the tmux session: Ctrl B D
  • Re-enter the session: tmux attach-session -t mypluto

6. Congiure your Nginx - the HTTP way with port 1234

  • /etc/nginx/conf.d/pluto_http.conf
  • URL: http//YOUR_DOMAIN_NAME:1234 or http//SERVER_IP_ADDRESS:1234
server {
  listen 1234;
  listen [::]:1234;
  
  server_name 240.5.113.13;

  location / {
    proxy_pass http://240.5.113.13:1234; 
  }
}

7. Configure your Nginx - the preferred HTTPS way with a URL path

  • /etc/nginx/nginx.conf

  • URL: http//YOUR_DOMAIN_NAME/pluto or http//SERVER_IP_ADDRESS/pluto
    …
    (Omitted common settings)
    http {
    ssl_session_cache shared:SSL:10m;
    #ssl_session_timeout 10m;
    ssl_session_timeout 1d;

    ssl_certificate /etc/nginx/certs/my_app.pem;
    ssl_certificate_key /etc/nginx/certs/my_passwordless.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!MD5;

    server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    return 301 https://$host$request_uri;
    }

    server {
    listen 443 ssl;
    #server_name localhost;
    server_name YOUR.DOMAIN.NAME;
    keepalive_timeout 70;

      # Nginx reverse proxy + URL rewrite
      # https://serverfault.com/questions/379675/nginx-reverse-proxy-url-rewrite
      location /pluto/ {                                         # Note the trailing slash!!!
          proxy_pass http://240.4.186.231:1234/; # Note the trailing slash!!! 
          proxy_redirect off;
    
          proxy_set_header Host $host;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-Host $host;
          proxy_set_header X-Forwarded-Proto $scheme;
      }	
    

    }
    (Omitted common settings)
    }

4 Likes

That is a great writeup. Have you tried using the juliaup installer ?

Thanks. No. I know nothing about the juliaup installer. Let me have a look at it.

Nginx is powerful. However, its configuration is not easy and obvious. Sometimes, I feel it’s confusing and frustrating, instead. If the above configuration in 7. is problematic as I encountered in a newer LXD-LXC 5.x cloud, try the following

        location /pluto/ { # Note the trailing slash!!!
            proxy_pass http://240.4.186.231:1234/; # Note the trailing slash!!!
            #proxy_buffering off;
            proxy_redirect off;

            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Proto $scheme;

            # WebSocket headers
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            proxy_set_header X-Scheme $scheme;
        }

My command to start Pluto (auto_reload_from_file=true ensures that *.jl files refresh correctly.):

julia> import Pluto; Pluto.run(;host="0.0.0.0", port=1234, launch_browser=false, require_secret_for_open_links=false, require_secret_for_access=false, auto_reload_from_file=true)
β”Œ Info:
β”” Go to http://0.0.0.0:1234/ in your browser to start writing ~ have fun!
β”Œ Info:
β”‚ Press Ctrl+C in this terminal to stop Pluto
β””