Home > Net >  Access WSL local server via HTTPS from other LAN device
Access WSL local server via HTTPS from other LAN device

Time:12-04

I use PHP NGINX DEBIAN WSL for local development and already managed to configure all of this to have two main things:

  • I can access my local server via HTTPS on the PC which is running WSL (i.e. I type https://127.0.0.1/ or https://project.loc in Chrome browser on Windows and I can see my local website fully working)
  • I can access my local server via HTTP from other devices in my local network, to do this I configured ports forwarding as described here: 1, 2, 3, 4, and now I can type http://192.168.1.2 on my iPhone for example, and my local website opens as expected.

But I can't figure out how to combine these two things so I can access my local website from iPhone via https://192.168.1.2:443.

I understand that one of my steps include installation of the root Certificate on my iPhone somehow, but we aren't there yet: right now I don't get any security-error messages on iPhone.
When I type https://192.168.1.2:443 on iPhone nothing happens, only endless loading.

Looks like Windows doesn't forward my request properly to https://127.0.0.1:443, although I have configured 443 port via netsh ... v4tov4 ... command in the same way as I configured 80 port (which works):

netsh interface portproxy add v4tov4 listenport=443 listenaddress=0.0.0.0 connectport=443 connectaddress=$($(wsl hostname -I).Trim());

What am I missing?

CodePudding user response:

It sounds like you have successfully configured your local server to be accessible via HTTPS on the PC running WSL, and you have also configured port forwarding to allow other devices on your local network to access the server via HTTP. However, you are unable to access the server via HTTPS from other devices on your local network.

One possible issue is that you may not have configured your server to listen on the correct IP address or port. When you type https://192.168.1.2:443 on your iPhone, this is trying to access the server at the IP address 192.168.1.2 on port 443. However, if your server is not configured to listen on this IP address and port, it will not be able to respond to the request.

To fix this, you will need to ensure that your server is listening on the correct IP address and port. This will typically involve configuring your server software (e.g. NGINX) to listen on the correct IP address and port. For example, in NGINX, you can use the listen directive to specify the IP address and port that the server should listen on.

Once you have configured your server to listen on the correct IP address and port, you will also need to ensure that your firewall is not blocking incoming connections to the server. If your firewall is blocking incoming connections, your server will not be able to respond to requests from other devices on your local network.

In addition to the above, you may also need to install a root certificate on your iPhone in order to access the server via HTTPS. When you access a server via HTTPS, the server will present a certificate to the client (in this case, your iPhone) to prove its identity. If the certificate is not trusted by the client, the client will typically display a security error message. In order to avoid this error, you will need to install the server's root certificate on your iPhone.

Once you have done all of the above, you should be able to access your server via HTTPS from other devices on your local network. It's worth noting that you will need to use the correct IP address and port in the URL (e.g. https://192.168.1.2:443) in order to access the server.

  • Related