I have a web server running on port 8080 on my Windows, and I want to access that from my WSL2 Ubuntu on Windows 11. But I am not able to do that. When I do curl, it get struck. curl localhost:8080 in wsl2.
How to reproduce:
- Run a server on Windows on any port; in my case, I used
php -S localhost:8080to run a web server on port 8080 on windows. - Go to WSL and do curl http://localhost:8080, and it gets stuck and sometimes
curl: (56) Recv failure: Connection reset by peer
What I have tried till now:
- wslconfig file ([wsl2] networkingMode=mirrored ) Cannot communicate with Windows localhost from WSL2
- Allowed inbound rule for my port in windows firewall -
New-NetFirewallRule -DisplayName "Allow phpServer 8080" -Direction Inbound -Protocol TCP -LocalPort 8080 -Action Allow - Tried hitting host.docker.internal (and host.internal) from wsl with that port, no success.
- Found similar issue on github, tried that too. https://github.com/microsoft/WSL/issues/4585#issuecomment-610061194
My main goal is that I want to configure nginx, which is running on Docker inside WSL. I want to access my web app, which is running on Windows port 8080. How to configure this in my nginx, but before doing all this, I don't know what to map localhost, host.docker.internal?
.env file
SPRING_PROFILES_ACTIVE=local
DOCKER_GATEWAY_HOST=172.17.0.1
eureka
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://${DOCKER_GATEWAY_HOST:-host.docker.internal}:8070/eureka/
DB_URL=jdbc:postgresql://${DOCKER_GATEWAY_HOST:-host.docker.internal}:5432/DB_NAME
DB_USER=user
DB_PASS=password
redis
REDIS_HOST=${DOCKER_GATEWAY_HOST:-host.docker.internal}
docker-compose.yml
networks:
test:
name: test
services:
rabbitmq:
image: rabbitmq
container_name: test-rabbitmq
environment:
- RABBITMQ_DEFAULT_USER=guest
- RABBITMQ_DEFAULT_PASS=guest
ports:
- 5672:5672
- 15672:15672
tty: true
redis:
image: redis/redis-stack
container_name: test-redis
ports:
- 6379:6379
- 16379:8001
restart: unless-stopped
tty: true
volumes:
- redis-data:/data
eureka:
image: springcloud/eureka # replaced for simplicity
container_name: test-eureka
env_file: .env
networks:
- test
ports:
- 8070:8070
tty: true
gatekeeper:
image: springcloud/gatekeeper # replaced for simplicity
container_name: test-gatekeeper
depends_on:
- eureka
env_file: .env
networks:
# - proxy
- test
ports:
- 8072:8072
tty: true
