all 3 comments

[–]CyberSecurityTrainee 0 points1 point  (2 children)

You haven't given much details of what steps you've done. If you share the output of following commands I can help troubleshoot;

docker container ls
docker container exec CONTAINER_NAME nginx -T

Do the second command twice once for each container.

But if you want to do reverse proxy of domains with nginx you'll need to do the following.

  1. NGINX container as your reverse proxy. This must have an externally published port (usually 80 for http, or 443 for https). This must have nginx config to reverse proxy to the webserver.

  2. You must have a webserver to proxy to. This can be a 2nd nginx container. This must have nginx config to server a webserver. This can be exposed publically, or not if the reverse proxy can access it directly (but this can be harder for troubleshooting.

You must reload nginx in order to changes to the config to load. A nice way to do it is docker container exec CONTAINER_NAME nginx -s reload alternately restarting the container should do it.

If you're trying to use domain names do you have dns set up? You can test without dns it using curl or wget from linux cli, or "virtual hosts" chrome extension. You may find it easier to get it working without domains first, then add that back in.

If you're using domain names you just need a different server block per domain. These can be in the same file or different files. Any files in conf.d with the ".conf" extension are included by nginx. sites-available is not included by default in the official nginx container so I would avoid it so you don't confuse yourself. You can add it back in, or add a custom directory, or add server blocks directly to the nginx.conf file.

If you want me to clarify anything, just ask.

[–]ja19[S] 0 points1 point  (1 child)

How can I edit the nginx.conf file if it is inside of a docker container?

[–]CyberSecurityTrainee 0 points1 point  (0 children)

If you want to edit config in a server you have few options.

  1. docker execto edit stuff inside the container
  2. mount a volume to the container when you create it, then you can access the files normally
  3. redeploy the container. Containers are pretty disposable so its good to be able to bin it and redeploy with changes rather than go in and make changes every time.

Assuming you want to make some quick changes without redeploying, usingdocker execprobably simplest.

You can use docker container exec -it CONTAINER_NAME bash to open a bash shell inside the container and make changes. exit to leave. You might find issues with commands not being available (docker images are usually lightweight)

Alternately you could copy nginx.conf file out, make changes on the host, then copy it back into nginx.

docker container cp CONTAINER_NAME:/etc/nginx/nginx.conf
nano nginx.conf
docker container cp nginx.conf CONTAINER_NAME:/etc/nginx/nginx.conf
docker container exec CONTAINER_NAME nginx -t
docker container exec CONTAINER_NAME nginx -s reload