Nginx and docker port problem

Sorry i am new to docker, i have self hosted vaultwarden running which can be visited by IP. Now i am working to add https using nginx but nginx can not be started because vaultwarden is using port 80. what is the work around to solve the port problem between nginx and vaultwarden docker, so the website can be reached using https.

Nginx:
nginx[13514]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx[13514]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx[13514]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx[13514]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx[13514]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx[13514]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx[13514]: nginx: [emerg] still could not bind()
vaultwarden.heremydomain.com systemd[1]: nginx.service: Control process exited, code=exited status=1
Apr 12 17:14:48 vaultwarden.heremydomain.com systemd[1]: nginx.service: Failed with result ‘exit-code’.

vaultwarden:

docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
91d3fd400ccb vaultwarden/server:latest /usr/bin/dumb-init … 9 hours ago Up 10 minutes (healthy) 0.0.0.0:80->80/tcp, :::80->80/tcp, 3012/tcp vaultwarden

This is fairly straight forward, in your docker command used to create the container you will want to change the port from the default 80 to something else unused like 8080. In the provided example the port is changed on the host to 8080, but the port inside the docker container remains 80

# using Docker:
docker run -d --name vaultwarden -v /vw-data/:/data/ -p 8080:80 vaultwarden/server:latest

You can view the wiki for more details.

If you will be using a reverse proxy with Nginx, I would also highly recommend enabling Websockets.

You may also check out the provided community examples for the proxy, there should be Nginx configs as well.

2 Likes