主配置文件太过杂乱与臃肿,所有进行拆分,方便配置文件的维护
创建辅配置文件存放的文件夹
mkdir /test
mkdir /nginx
// /test/nginx
新增辅配置文件
只需要新增一个server模块就行了
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /portainer/ {
proxy_pass http://localhost:8000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
主配置文件修改
删除多余项,在http模块中新增 include /test/nginx/*.conf;
#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 /test/nginx/*.conf;
}
检查重启
# 校验配置文件
nginx -t
# 重启nginx
nginx -s reload