我试图运行一个NGINX容器,从外观上看,它启动时没有问题,但当试图访问任何页面时,它的主机我“无法连接”,它不会给予通常的NGINX欢迎或NGINX错误。
启动它时,我得到以下日志:
$ sudo docker-compose up
Starting production_nginx ... done
Attaching to production_nginx
production_nginx | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
production_nginx | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
production_nginx | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
production_nginx | 10-listen-on-ipv6-by-default.sh: /etc/nginx/conf.d/default.conf is not a file or does not exist, exiting
production_nginx | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
production_nginx | /docker-entrypoint.sh: Configuration complete; ready for start up
字符串
我的docker-compose.yml看起来像这样:
version: "3.7"
services:
nginx:
image: nginx:latest
container_name: production_nginx
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- /etc/letsencrypt/:/etc/letsencrypt/
- /opt/nginx_cache/:/opt/nginx_cache/
- /var/home/core/docker/nginx/dhparam.pem:/etc/nginx/dhparam.pem
- /var/home/core/docker/nginx/conf.d/:/etc/nginx/conf.d/
- /var/home/core/docker/files/:/var/home/core/docker/files/
- /var/home/core/docker/nginx/nginx.conf:/etc/nginx/nginx.conf
- /var/log/nginx/:/var/log/nginx/:Z
networks:
- proxynet
- abnet
- dsnet
networks:
proxynet:
name: source_network
abnet:
name: one_network
dsnet:
name: two_network
型
我已经进入了NGINX容器的shell,并测试了所有通过测试的配置文件。
还有什么可能导致此问题?
编辑添加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 {
include /etc/nginx/mime.types;
default_type application/octet-stream;
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;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
client_max_body_size 50M;
client_body_buffer_size 50M;
ssl_session_timeout 10m;
ssl_ecdh_curve secp384r1;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_stapling on;
ssl_stapling_verify on;
proxy_cache_path /opt/nginx_cache levels=1:2 keys_zone=nginx_cache:60m max_size=300m inactive=24h;
proxy_cache_key "$scheme$request_method$host$request_uri";
proxy_cache_methods GET HEAD;
}
型
1条答案
按热度按时间zlhcx6iw1#
在
nginx.conf
文件的顶部,将nginx配置为 * 不 * 作为守护程序运行:字符串
默认值是
on
。所以如果不指定,nginx将作为守护进程运行。这意味着nginx将在后台运行,并将控制权给予给调用环境。这反过来会导致docker容器安静地退出。以下是官方文档,并有相当简短的解释:
确定nginx是否应该成为守护进程。主要在开发过程中使用。
另一种选择是在
docker-compose.yml
中使用command:
指令:command: ["nginx", "-c", "/etc/nginx/nginx.conf", "-g", "daemon off;"]
个由于您已经有了自己的
nginx.conf
,因此在那里配置它可能会更清楚。