我安装了openresty alpine docker镜像并安装了conf.d在其中定义服务器。很好。
接下来,我要更改nginx.conf并设置worker_process=auto
。但是worker_processes
是在nginx.conf中定义的。我尝试将Docker-compose文件中的nginx.conf
卷挂载为:
volumes:
- ./conf.d:/etc/nginx/conf.d
- ./conf/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf
但是,它会在nginx.conf
中创建目录./conf
如何安装/修改nginx.conf?
答案 0 :(得分:1)
如果要更新nginx根配置,则使用错误的Docker目录挂载它。
Nginx配置文件
Docker工具会安装自己的
nginx.conf
文件。如果你想 直接覆盖它,您可以将其替换为自己的Dockerfile或通过 批量绑定安装。对于Linux映像,nginx.conf的指令包括
/etc/nginx/conf.d/*.conf
;所以那所有的nginx配置 目录将包括在内。默认虚拟主机配置具有 原始的OpenResty配置并复制到/etc/nginx/conf.d/default.conf
。
docker run -v /my/custom/conf.d:/etc/nginx/conf.d openresty/openresty:alpine
第二件事,最好使用绝对路径进行安装。
docker run -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf openresty/openresty:1.15.8.2-1-alpine
或
docker run -v abs_path/nginx.conf:/etc/nginx/nginx.conf openresty/openresty:1.15.8.2-1-alpine
Openresty配置:
docker run -v $PWD/conf/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf openresty/openresty:1.15.8.2-1-alpine
您应该挂载确切的文件,否则它将破坏容器。
这是/usr/local/openresty/nginx/conf/nginx.conf
# nginx.conf -- docker-openresty
#
# This file is installed to:
# `/usr/local/openresty/nginx/conf/nginx.conf`
# and is the file loaded by nginx at startup,
# unless the user specifies otherwise.
#
# It tracks the upstream OpenResty's `nginx.conf`, but removes the `server`
# section and adds this directive:
# `include /etc/nginx/conf.d/*.conf;`
#
# The `docker-openresty` file `nginx.vh.default.conf` is copied to
# `/etc/nginx/conf.d/default.conf`. It contains the `server section
# of the upstream `nginx.conf`.
#
# See https://github.com/openresty/docker-openresty/blob/master/README.md#nginx-config-files
#
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include 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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}