Nginx 配置daemon off;
中有一个指令集/root/nginx.conf
。
我正在尝试使用以下命令在 docker 下运行它:
sudo docker run --name nginx-redirect -p 3128:3128 -v /root/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx
但什么都没有发生(除了 Docker 输出的容器 ID;我认为这应该意味着一切正常),并且没有netstat -tulpn
显示docker/nginx
容器和3128
端口,我错在哪里?
/root/nginx.conf
:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
daemon off;
events {
worker_connections 768;
}
http {
server {
listen 3128;
location / {
proxy_pass http://example.com;
}
}
}
答案1
nginx 容器默认运行daemon off;
,你可以从 Dockerfile 中验证这一点
FROM debian:jessie
MAINTAINER NGINX Docker Maintainers "[email protected]"
ENV NGINX_VERSION 1.10.2-1~jessie
RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 \
&& echo "deb http://nginx.org/packages/debian/ jessie nginx" >> /etc/apt/sources.list \
&& apt-get update \
&& apt-get install --no-install-recommends --no-install-suggests -y \
ca-certificates \
nginx=${NGINX_VERSION} \
nginx-module-xslt \
nginx-module-geoip \
nginx-module-image-filter \
nginx-module-perl \
nginx-module-njs \
gettext-base \
&& rm -rf /var/lib/apt/lists/*
# forward request and error logs to docker log collector
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log
EXPOSE 80 443
CMD ["nginx", "-g", "daemon off;"]
因此您需要从 nginx 文件中删除 daemon 指令并运行容器,它就应该正常工作。