【发布时间】:2021-12-09 17:42:29
【问题描述】:
我正在尝试使用 jwilder/nginx-proxy 容器设置反向代理。
我有一个小型 Express 应用:
var express = require("express");
var app = express();
app.get("/api", (req, res, next) => {
res.json({ hello: "world" });
});
app.listen(3000, () => {
console.log("Server running on port 3000");
});
还有一个docker-compose.yml:
version: "3.4"
services:
reverse-proxy:
image: jwilder/nginx-proxy
ports:
- 80:80
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
networks:
- testt
testt:
container_name: testt
image: node:lts
working_dir: /var/www/html/app/
entrypoint: /bin/bash
environment:
- HOST=0.0.0.0
- VIRTUAL_HOST=testt.dev # for reverse proxy
- VIRTUAL_PORT=3000 # for reverse proxy
ports:
- 3000:3000
volumes:
- ./testt/:/var/www/html/app
tty: true
networks:
- testt
networks:
testt:
external: true
这就是我设置的所有内容。没有别的了。
当我运行localhost:3000/api 时,我得到了预期的结果{"hello":"world"}。当我在浏览器中运行 http://testt.dev/api 时,我希望得到相同的结果,但它不起作用(DNS_PROBE_FINISHED_NXDOMAIN)。
我还需要设置什么以及在哪里设置? 我必须为 HOSTS 文件设置一些内容吗?
谢谢
编辑: 码头工人日志:
Setting up DH Parameters..
forego | starting dockergen.1 on port 5000
forego | starting nginx.1 on port 5100
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: using the "epoll" event method
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: nginx/1.21.3
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: built by gcc 8.3.0 (Debian 8.3.0-6)
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: OS: Linux 5.10.47-linuxkit
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: getrlimit(RLIMIT_NOFILE): 1048576:1048576
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: start worker processes
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: start worker process 27
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: start worker process 28
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: start worker process 29
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: start worker process 30
dockergen.1 | 2021/12/09 09:39:36 Template error: open /etc/nginx/certs: no such file or directory
dockergen.1 | 2021/12/09 09:39:36 Generated '/etc/nginx/conf.d/default.conf' from 2 containers
dockergen.1 | 2021/12/09 09:39:36 Running 'nginx -s reload'
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: signal 1 (SIGHUP) received from 32, reconfiguring
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: reconfiguring
dockergen.1 | 2021/12/09 09:39:36 Watching docker events
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: using the "epoll" event method
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: start worker processes
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: start worker process 37
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: start worker process 38
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: start worker process 39
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: start worker process 40
dockergen.1 | 2021/12/09 09:39:36 Template error: open /etc/nginx/certs: no such file or directory
dockergen.1 | 2021/12/09 09:39:36 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
nginx.1 | 2021/12/09 09:39:36 [notice] 27#27: gracefully shutting down
nginx.1 | 2021/12/09 09:39:36 [notice] 28#28: gracefully shutting down
nginx.1 | 2021/12/09 09:39:36 [notice] 30#30: gracefully shutting down
nginx.1 | 2021/12/09 09:39:36 [notice] 29#29: gracefully shutting down
nginx.1 | 2021/12/09 09:39:36 [notice] 27#27: exiting
nginx.1 | 2021/12/09 09:39:36 [notice] 30#30: exiting
nginx.1 | 2021/12/09 09:39:36 [notice] 29#29: exiting
nginx.1 | 2021/12/09 09:39:36 [notice] 28#28: exiting
nginx.1 | 2021/12/09 09:39:36 [notice] 27#27: exit
nginx.1 | 2021/12/09 09:39:36 [notice] 29#29: exit
nginx.1 | 2021/12/09 09:39:36 [notice] 30#30: exit
nginx.1 | 2021/12/09 09:39:36 [notice] 28#28: exit
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: signal 17 (SIGCHLD) received from 28
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: worker process 27 exited with code 0
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: worker process 28 exited with code 0
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: signal 29 (SIGIO) received
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: signal 17 (SIGCHLD) received from 27
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: worker process 30 exited with code 0
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: signal 29 (SIGIO) received
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: signal 17 (SIGCHLD) received from 29
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: worker process 29 exited with code 0
nginx.1 | 2021/12/09 09:39:36 [notice] 22#22: signal 29 (SIGIO) received
【问题讨论】:
-
您是否设置了 DNS 以便
testt.dev解析到您的计算机? -
无论如何。我必须为主机文件设置一些东西吗?
-
是的,这将在开发过程中起作用。将
127.0.0.1 testt.dev添加到/etc/hosts。 -
好吧,不工作。我希望我需要设置类似的东西......但它没有帮助。奇怪
标签: node.js docker nginx nginx-reverse-proxy