尝试通过docker compose运行nginx和Web应用程序
dockerfile
FROM node:12.16.2 as build
RUN mkdir /app
COPY package*.json ./
RUN npm install
COPY . /app
RUN npm run-script build
COPY --from=build /app/build /var/www/roundmap.app
EXPOSE 3000
nginx配置defauls.conf
server {
listen 80;
listen 443 ssl;
listen 3000;
server_name *.roundmap.app 185.146.157.206;
root /var/www/roundmap.app;
index index.html;
ssl_certificate /etc/ssl/roundmap/roundmap.crt;
ssl_certificate_key /etc/ssl/roundmap/roundmap.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
if ($scheme = http) {
return 301 https://$server_name$request_uri;
}
location / {
proxy_pass https://app:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
docker-compose.yml
version: "4"
services:
app:
build: roundmap/
container_name: app
ports:
- 3000:3000
nginx:
image: nginx:1.17.2-alpine
container_name: nginx
ports:
- 80:80
- 443:443
links:
- app
volumes:
- ./default.conf:/etc/nginx/conf.d/default.conf
- /etc/ssl/roundmap/roundmap.crt:/etc/ssl/roundmap/roundmap.crt
- /etc/ssl/roundmap/roundmap.key:/etc/ssl/roundmap/roundmap.key
通过docker-compose up运行 并得到错误
nginx | 2020/07/20 16:39:19 [emerg] 1#1:在/etc/nginx/conf.d/default.conf:22的上游“应用”中找不到主机 nginx | nginx:在/etc/nginx/conf.d/default.conf:22的上游“应用”中找不到[emerg]主机 nginx以代码1退出
Сan,请帮助我在哪里弄错了?
答案 0 :(得分:0)
在您的default.conf
中,将https://app:3000
替换为http://app:3000
,因为Nginx本身正在进行SSL终止,而应用仍在使用http。
更新您的docker-compose.yaml
不推荐使用depends_on
而不是links
。
version: "3.8"
services:
app:
build: roundmap/
container_name: app
command: [ "node", "app.js"]
ports:
- 3000:3000
nginx:
image: nginx:1.17.2-alpine
container_name: nginx
ports:
- 80:80
- 443:443
depends_on:
- app
volumes:
- ./default.conf:/etc/nginx/conf.d/default.conf
- /etc/ssl/roundmap/roundmap.crt:/etc/ssl/roundmap/roundmap.crt
- /etc/ssl/roundmap/roundmap.key:/etc/ssl/roundmap/roundmap.key