【发布时间】:2019-01-26 12:03:20
【问题描述】:
我正在尝试在我的 Mac 上本地设置一个简单的 Web 堆栈。
- nginx 作为反向代理
- react web 应用 #1 将在 localhost 上提供服务
- react web 应用程序 #2 将在 demo.localhost 上提供
我正在使用 docker-compose 一次旋转所有服务,这是文件:
version: "3"
services:
nginx:
container_name: nginx
build: ./nginx/
ports:
- "80:80"
networks:
- backbone
landingpage:
container_name: landingpage
build: ./landingpage/
networks:
- backbone
expose:
- 3000
frontend:
container_name: frontend
build: ./frontend/
networks:
- backbone
expose:
- 3001
networks:
backbone:
driver: bridge
这里是 nginx 配置文件(使用 Dockerfile 中的 COPY 命令复制到容器中):
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
gzip on;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain text/css
application/x-javascript text/xml
application/xml application/xml+rss
text/javascript;
upstream landingpage {
server landingpage:3000;
}
upstream frontend {
server frontend:3001;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://landingpage;
}
}
server {
listen 80;
server_name demo.localhost;
location / {
proxy_pass http://frontend;
}
}
}
我可以成功运行docker-compose up,但只能打开web应用,而demo.localhost没有。
我还更改了我的 Mac 上的主机文件内容,所以我有
127.0.0.1 localhost
127.0.0.1 demo.localhost
无济于事。
恐怕我错过了什么,因为我既不是 Web 开发专家,也不是 docker 或 nginx!
【问题讨论】:
-
你找到答案了吗?我正在尝试这样做
-
我们最终能够使它在生产中工作,我将在下面发布解决方案
标签: docker nginx localhost subdomain local