Skip to content

Instantly share code, notes, and snippets.

@azechi
Last active April 18, 2023 09:06
Show Gist options
  • Save azechi/d59aef93a463091563ed42ea4fe0e25c to your computer and use it in GitHub Desktop.
Save azechi/d59aef93a463091563ed42ea4fe0e25c to your computer and use it in GitHub Desktop.
Accessing WSL2 Web server via HTTPS on LAN

宅内LANでWindows機のローカルIPアドレスを固定化する

ネームサーバーでlocaldev.azechi.netを宅内LANのWin機のアドレスに設定する

localdev.azechi.netのサーバー証明書をLet's Encryptに発行してもらう

Docker Descktopを使ってnginxのhttpsリバースプロキシを実行する

default.conf.template
map $http_upgrade $connection_upgrade {
  default upgrade;
  '' close;
}

server {
  listen 80;
  listen [::]:80;
  listen 443 ssl;
  listen [::]:443 ssl;
  server_name ${HOST};

  ssl_certificate /certs/live/${HOST}/fullchain.pem;
  ssl_certificate_key /certs/live/${HOST}/privkey.pem;

  location / {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;

    proxy_pass http://host.docker.internal:${LOCALPORT};
  }
}
docker run
  -it
  --rm
  -p 80:80
  -p 443:443
  --mount type=bind,source=$PWD/default.conf.template,target=/etc/nginx/templates/default.conf.template
  --mount type=bind,source=$HOME/cert/etc/,target=/certs
  -e HOST=localdev.azechi.net
  -e LOCALPORT=5174
  nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment