有两个配置文件/etc/Nginx/Nginx.conf
、/etc/Nginx/conf.d/default.conf
其中Nginx.conf
在其http
块下导入了/etc/Nginx/conf.d/*.conf
user Nginx;
worker_processes auto;
error_log /var/log/Nginx/error.log notice;
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;
#gzip on;
include /etc/Nginx/conf.d/*.conf;
}
因此/etc/Nginx/conf.d/*.conf
中的配置文件必须是server
块
而server
块中默认监听80端口
然后default.conf
监听了localhost的80端口
所以如果你创建了一个新的配置文件在/etc/Nginx/conf.d
下,而且你也想要监听80端口,配置文件就会失效
因为端口冲突了,选用的是default.conf
中的配置
所以如果你想在镜像的默认配置下将配置文件模块化,应该是不可能的
要么去修改default.conf使其在它的server块中导入你的只写了location块的配置文件
要么直接覆盖default.conf,在docker中,我感觉直接覆盖比较简单,因为default.conf中的配置本身比较简单,去掉注释其实就没几行,而修改default.conf就没那么简单了
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
root /usr/share/Nginx/html;
index index.html index.htm;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。