我有这段代码:
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 < / p>
答案 0 :(得分:1)
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;
}
}