0%

nginx配置路由转发

获取ngxin

docker pull hub.deri.org.cn/library/nginx

编写nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
    
    upstream taskservice{
        server 172.16.0.9:28080;
    }

    upstream authservice{
        server 172.16.0.9:25050;
    }

    upstream dbcservice{
        server 172.16.0.9:28082;
    }

    upstream hbcservice{
        server 172.16.0.9:26060;
    }

    upstream graphservice{
        server 172.16.0.9:29090;
    }

    server {
        listen	80 default_server;
        server_name _;
    location /ts {
        proxy_pass	http://taskservice;
    }
        location /auth {
            proxy_pass  http://authservice;
        }
        location /dbc {
            proxy_pass  http://dbcservice;
        }
        location /hbc {
            proxy_pass  http://hbcservice;
        }
        location /graph {
            proxy_pass  http://graphservice;
        }
    }
}

启动nginx容器

docker run -d --name nginx  -p 8080:80 -v /root/nginx/nginx.conf:/etc/nginx/nginx.conf  nginx