如何解决如何使用 docker-compose 将 nginx 配置为 nodejsexpress应用程序的反向代理
我正在尝试使用 nginx 作为 nodejs 应用程序的反向代理构建一个 docker-compose 文件。
总结一下我的想法是: 浏览器(本地主机:8000)-> Nginx(端口:80)-> 节点(端口:3000)-> 返回我的“Hello World!”
我的文件:
docker-compose.yaml
version: '3'
services:
app:
build:
context: ./node
dockerfile: Dockerfile
image: vitordarochacamargo/node
container_name: node
networks:
- desafio-network
nginx:
build:
context: ./nginx
dockerfile: Dockerfile
image: vitordarochacamargo/nginx
container_name: nginx
networks:
- desafio-network
ports:
- "8000:80"
networks:
desafio-network:
driver: bridge
nginx/Dockerfile
FROM nginx:1.15.0-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
EXPOSE 80
CMD ["tail","-f","/dev/null"]
nginx/nginx.conf
server {
listen 80;
server_name vitordarochacamargo/ngix;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass vitordarochacamargo/node:3000;
}
}
节点/Dockerfile
FROM node:15
WORKDIR /usr/src/app
COPY index.js .
RUN npm install express
EXPOSE 3000
CMD [ "node","index.js" ]
节点/index.js
const express = require('express')
const app = express()
const port = 3000
app.get('/',(req,res) => {
res.send('<h1>Full Cycle Rocks!</h1>')
})
app.listen(port,() => {
console.log(`listening at http://localhost:${port}`)
})
运行应用 -> docker-compose up -d --build
当然我遗漏了一些东西,但是我最近是如何开始学习 docker、docker-compose 和 nginx 的,我无法弄清楚,我做错了什么。
如果你们需要更多信息,请告诉我。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。