简体   繁体   中英

Nginx multiple server ports configuration with docker

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!

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM