简体   繁体   English

更改 nginx conf 文件

[英]changing nginx conf file

I installed openresty alpine docker image and mounted conf.d to define the server in there.我安装了 openresty alpine docker 镜像并安装了 conf.d 来定义服务器。 It works fine.它工作正常。

Next, I want to change nginx.conf and set worker_process=auto .接下来,我想更改 nginx.conf 并设置worker_process=auto However worker_processes are defined in nginx.conf.但是worker_processes是在 nginx.conf 中定义的。 I tried to volume mount nginx.conf in Docker-compose file as:我尝试在 Docker-compose 文件中将nginx.conf卷挂载为:

volumes:
 -  ./conf.d:/etc/nginx/conf.d  
 -  ./conf/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf

however, it creates a directory nginx.conf in ./conf但是,它会在./conf创建一个目录nginx.conf

How can I mount/modify nginx.conf?如何挂载/修改 nginx.conf?

You are mounting it with the wrong directory of the Docker if you want to update nginx root configuration.如果您想更新 nginx 根配置,您将使用错误的 Docker 目录安装它。

Nginx Config Files Nginx 配置文件

The Docker tooling installs its own nginx.conf file. Docker 工具安装它自己的nginx.conf文件。 If you want to directly override it, you can replace it in your own Dockerfile or via volume bind-mounting.如果你想直接覆盖它,你可以在你自己的 Dockerfile 中或者通过卷绑定安装来替换它。

For the Linux images, that nginx.conf has the directive include /etc/nginx/conf.d/*.conf ;对于 Linux 映像,该 nginx.conf 具有指令 include /etc/nginx/conf.d/*.conf so all nginx configurations in that directory will be included.因此将包含该目录中的所有 nginx 配置。 The default virtual host configuration has the original OpenResty configuration and is copied to /etc/nginx/conf.d/default.conf .默认的虚拟主机配置具有原始的 OpenResty 配置并复制到/etc/nginx/conf.d/default.conf

docker run -v /my/custom/conf.d:/etc/nginx/conf.d openresty/openresty:alpine

Second thing, Better to use an absolute path for mounting.第二件事,最好使用绝对路径进行安装。

docker run -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf openresty/openresty:1.15.8.2-1-alpine

or或者

docker run -v abs_path/nginx.conf:/etc/nginx/nginx.conf openresty/openresty:1.15.8.2-1-alpine

Openresty config: Openresty 配置:

docker run -v $PWD/conf/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf openresty/openresty:1.15.8.2-1-alpine

You should mount exact file, otherwise it will break the container.您应该挂载确切的文件,否则会破坏容器。

在此处输入图片说明 here is the default config for /usr/local/openresty/nginx/conf/nginx.conf这是/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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM