1

I have a local Nginx installation that uses a custom config file to route different services and a web application to a single port.

The Nginx configuration file looks something like:

server {
        listen       8080;
        server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   html;
        index  index.html index.htm;
    }

    location /api/login {
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server %host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://localhost:8181;
        client_max_body_size 10M;
    }

    location /api/accountopening {
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server %host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://localhost:8282;
        client_max_body_size 10M;
    }
...

I am trying to do the same thing with Docker and the Nginx official image in DockerHub, but I haven't been able to.
In their documentation they say I should do something like:

docker run --name cor-nginx \
           -v ~/dev/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro \
           -d \
           -p 8080:80 nginx

to create a volume and specify a custom config file but no results so far.

Has anyone done anything similar ?

Thanks a lot in advance!

1 Answers1

0

Please exec to your Nginx container and check if a path to configuration files is valid.

I think you pass the wrong path, default it is: /etc/nginx/conf.d.

Also, you should use Dockerfile to build your changed image, it's better and more clarify than passing options as an argument to Docker. You should also delete existing - default Nginx configurations.

I think it will be so helpful for you:

how to run nginx docker container with custom config?

  • 1
    Thanks a lot for your response. I got the right config in the container now although I haven't been able to do what I wanted. I don't even now if it makes sense to proxy services running in my host through my nginx container – LUIS SANTOS Jul 24 '18 at 22:33