To deploy Portainer behind an nginx proxy in a Docker standalone scenario you must use a Docker Compose file. In the following docker-compose.yml you will find the configuration of the nginx proxy and the Portainer Server.
This example uses the excellent nginxproxy/nginx-proxy image as the proxy container, which requires no additional configuration beyond the two environment variables added to the portainer container's definition.
To start working with this recipe, change the VIRTUAL_HOST value then deploy Portainer by running the following:
docker-compose up -d
When this has finished, run docker ps . You should see an output similar to this:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8c8f2eac7c9a portainer/portainer-ee:2.24.0 "/portainer -H unix:…" 4 minutes ago Up 4 minutes 9000/tcp, 0.0.0.0:8000->8000/tcp, :::8000->8000/tcp, 9443/tcp portainer_portainer_1
3e7c8b5d71d7 nginxproxy/nginx-proxy "/app/docker-entrypo…" 4 minutes ago Up 4 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp portainer_nginx-proxy_1
Once the deployment has finished you can browse portainer.yourdomain.com.
Deploying in a Docker Swarm scenario
Deploying Portainer in Docker Swarm behind nginx has similar steps to the Docker Standalone scenario. Before deploying, you need to create two elements: networks and volumes.
This deployment assumes you are running one manager node. If you are using multiple managers we advise reading this knowledge base article before proceeding.
First, create two networks:
One for the agent and the communication with the Portainer Server.
One to 'expose' the Portainer container to the same network as the reverse proxy.
docker network create -d overlay proxy
docker network create -d overlay agent_network
Next, create the volume:
docker volume create portainer_data
And finally, save the following recipe as portainer.yml: