主配置文件太过杂乱与臃肿,所有进行拆分,方便配置文件的维护

创建辅配置文件存放的文件夹

  1. mkdir /test
  2. mkdir /nginx
  3. // /test/nginx

新增辅配置文件

只需要新增一个server模块就行了

  1. server {
  2. listen 80;
  3. server_name localhost;
  4. #charset koi8-r;
  5. #access_log logs/host.access.log main;
  6. location /portainer/ {
  7. proxy_pass http://localhost:8000/;
  8. proxy_http_version 1.1;
  9. proxy_set_header Upgrade $http_upgrade;
  10. proxy_set_header Connection "Upgrade";
  11. }
  12. }

主配置文件修改

删除多余项,在http模块中新增 include /test/nginx/*.conf;

  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. # '$status $body_bytes_sent "$http_referer" '
  15. # '"$http_user_agent" "$http_x_forwarded_for"';
  16. #access_log logs/access.log main;
  17. sendfile on;
  18. #tcp_nopush on;
  19. #keepalive_timeout 0;
  20. keepalive_timeout 65;
  21. #gzip on;
  22. # 引入其他的配置文件进行配置
  23. include /test/nginx/*.conf;
  24. }

检查重启

  1. # 校验配置文件
  2. nginx -t
  3. # 重启nginx
  4. nginx -s reload