Skip to content

Instantly share code, notes, and snippets.

@YongmingZhao
Created January 30, 2023 11:01
Show Gist options
  • Save YongmingZhao/23e32d4e868b1be821256342e70bcef2 to your computer and use it in GitHub Desktop.
Save YongmingZhao/23e32d4e868b1be821256342e70bcef2 to your computer and use it in GitHub Desktop.
Nginx https bridge

Create a self-signed ssl server

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt

Add config

ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;

Create a password file

sudo sh -c "echo -n 'sammy:' >> /etc/nginx/.htpasswd"
sudo sh -c "openssl passwd -apr1 >> /etc/nginx/.htpasswd"

Add basic authentication config

location / {
     auth_basic "Private RPC";
     auth_basic_user_file /etc/nginx/.htpasswd;
     proxy_pass http://127.0.0.1:8546;
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection "upgrade";
}

On another machine, add config

location / {
     proxy_pass https://domain;
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection "upgrade";
     proxy_set_header Authorization "Basic AuthString";
     proxy_pass_header Authorization;
}

Use command echo -n "user:pass" | base64 to generate AuthString

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment