dsriseah / ursys

an opinionated javascript library for prototyping realtime web apps
1 stars 2 forks source link

WSS and EXPRESS can share HTTP Port #3

Closed dsriseah closed 1 month ago

dsriseah commented 1 month ago

As I look into supporting https on remote servers like Digital Ocean, I think the architecture looks like this:

Proof of Concept Steps

Tests Passed

Bugs Fixed

Enhancements

dsriseah commented 1 month ago

TESTING on DIGITAL OCEAN

  1. pull branch on digital ocean (DO) server
  2. confirm that nginx is configured using an appropriate proxy definition file (see below)
  3. open a terminal window on DO, browse to repo directory
  4. npm ci
  5. cd _ur
  6. ur net start
  7. on browser machines, open three different windows (use chrome, firefox) and open javascript consoles
  8. browse to https://do-server/location (e.g. ursys.sri.xyz/app)...note this is https
  9. In browser windows, reload each one in a row.
  10. Check console for message CLIENT TEST UR_001 resolved with []. First window will return empty array, second window will return with {uaddr}, and third window will return with [ {uaddr}, {uaddr} ]
  11. Try reloading one of the windows, which should work as an array with two elements
  12. Also check the server's terminal output to detect that client connect/disconnect is working

NGINX EXAMPLE CONFIG

Described in Guide: Securing URSYS.

server {

    root /var/www/ursys_dsri_xyz/html;
    index index.html index.htm index.nginx-debian.html;

    server_name ursys.dsri.xyz ;

    location /app/ {
      proxy_pass http://127.0.0.1:8080/;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      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;
      proxy_set_header X-Forwarded-Host $server_name;
      proxy_read_timeout 7200;  # 2 hours
    }

    location / {
      try_files $uri $uri/ =404;
    }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/dsri.xyz/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/dsri.xyz/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {

    if ($host ~ ^[^.]+\.dsri\.xyz$) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = ursys.dsri.xyz) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    listen [::]:80;

    server_name ursys.dsri.xyz ;
    return 404; # managed by Certbot

}
dsriseah commented 1 month ago

TESTING ON LOCAL DEV

The usual instructions apply:

  1. pull branch locally
  2. npm ci && cd _ur
  3. ur net start
  4. Follow steps 7 onward from TESTING ON DIGITAL OCEAN, substituting http://127.0.0.1:8080