【发布时间】:2018-04-05 02:35:13
【问题描述】:
我的环境建立在 docker 容器上(在 boot2docker 中)。我有以下 docker-compose.yml 文件来快速设置 nginx 和 nexus 服务器:
version: '3.2'
services:
nexus:
image: stefanprodan/nexus
container_name: nexus
ports:
- 8081:8081
- 5000:5000
nginx:
image: nginx:latest
container_name: nginx
ports:
- 5043:443
volumes:
- /opt/dm/nginx2/nginx.conf:/etc/nginx/nginx.conf:ro
Nginx 有如下配置(nginx.conf)
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
proxy_send_timeout 120;
proxy_read_timeout 300;
proxy_buffering off;
keepalive_timeout 5 5;
tcp_nodelay on;
server {
listen 80;
server_name demo.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name demo.com;
# allow large uploads of files - refer to nginx documentation
client_max_body_size 1024m;
# optimize downloading files larger than 1G - refer to nginx doc before adjusting
#proxy_max_temp_file_size 2048m
#ssl on;
#ssl_certificate /etc/nginx/ssl.crt;
#ssl_certificate_key /etc/nginx/ssl.key;
location / {
proxy_pass http://nexus:8081/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto "https";
}
}
}
Nexus 似乎运作良好。我在 docker 主机上成功调用了curl http://localhost:8081。这将返回我连接登录站点的 html。现在我想试试 nginx 服务器。它被配置为侦听 443 端口,但 SSL 现在被禁用(我想在深入研究 SSL 配置之前对其进行测试)。如您所见,我的 ngix 容器将端口 443 映射到端口 5043。因此,我尝试使用以下 curl 命令:curl -v http://localhost:5043/。现在我希望我的 http 请求将被发送到 nginx 并代理到proxy_pass http://nexus:8081/; nexus。 Nexus 主机名在 docker 容器网络中可见,并且可以从 nginx 容器中访问。不幸的是,我收到了:
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 5043 (#0)
> GET / HTTP/1.1
> Host: localhost:5043
> User-Agent: curl/7.49.1
> Accept: */*
>
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server
我正在检查 nginx 日志、错误、访问但这些日志是空的。有人可以帮我解决这个问题吗?它应该只是代理请求的一个简单示例,但也许我误解了一些概念?
【问题讨论】:
-
日志必须存储在某个地方...试试
docker-compose logs并请显示输出。 -
挂载目录工作正常。我猜安装不适用于这个容器。使用 $ docker logs CONTAINER_ID 检查 nginx 容器日志
-
什么都没有,日志是空的,似乎没有什么东西在访问代理服务器
-
你可以尝试在没有卷的情况下运行 nginx
-
为什么?感谢音量,我有 nginx.conf 文件。没有它,我的测试将毫无意义。