docker – 如何使用nginx和terraform配置两个实例?

我有这个代码:

resource "docker_image" "nginx" {                        
  name = "nginx:1.11-alpine"                             
}                                                        
resource "docker_container" "nginx-server" {          
  name = "nginx-server"                               
  image = "${docker_image.nginx.latest}"              
  ports {                                             
    internal = 80                                     
    external = 80                                     
  }                                                   
  volumes {                                           
    container_path  = "/usr/share/nginx/html"         
    host_path = "/home/scrapbook/tutorial/www"        
    read_only = true                                  
  }                                                   
} 

在一个terraform文件(.tf)中…我想配置在同一台服务器上的两个不同端口中提供的两个Web程序实例.

resource "docker_container" "Odoo-iku_1" {                 
  name  = "Odoo-iku 1"                                     
  image = "ikusolutions/odoo-iku:latest"                 
  links = ["db"]                                         
  ports {                                                
    external = 8070                                      
    internal = 8069                                   
  }    
}

resource "docker_container" "Odoo-iku_2" {                 
  name  = "Odoo-iku 2"                                     
  image = "ikusolutions/odoo-iku:latest"                 
  links = ["db"]                                         
  ports {                                                
    external = 8071                                      
    internal = 8069                                   
  }    
}

如何让nginx将外部端口8070和8071用于域名?例如:端口8070指向https://iku.solutions,端口8071指向https://demo.iku.solutions

解决方法:

Nginx根据您配置的方式路由到达服务器的流量.
在您的情况下,您希望将nginx配置为反向代理,根据他们尝试访问的服务器名称来路由请求.假设Odoo-iku 1 Odoo-iku 2的请求分别来自Odoo-iku1.example.com和Odoo-iku2.example.com,此配置应该适合您.

server {
  listen      8001 default_server;
  server_name Odoo-iku1.example.com;
  location / {
    proxy_pass       http://127.0.0.1:8071;
  }
}

server {
  listen      8002 default_server;
  server_name Odoo-iku2.example.com;
  location / {
    proxy_pass       http://127.0.0.1:8070;
  }
}

upstream main {
  server 127.0.0.1:8001;
  server 127.0.0.1:8002;
}

server {
  listen      80;
  server_name example.com;
  location / {
    proxy_pass http://main;
  }
}
上一篇:python – Odoo 8.0 product_product继承扩展类


下一篇:Odoo甘特图