Nginx Proxymanager“map”指令不被允许

Nginx Proxymanager“map”指令不被允许

我现在正在部署我的 Django 项目,我在 digital ocean 上有一个服务器,我正在设置 nginx 代理管理器。我已经为 Portainer 添加了 SSL 证书,当我将它添加到主容器时,我收到一个内部错误:

nginx: [emerg] "map" directive is not allowed here in /data/nginx/proxy_host/2.conf:32

这是我的文件2.conf:

map $scheme $hsts_header {
    https   "max-age=63072000; preload";
}

server {
  set $forward_scheme http;
  set $server         "api";
  set $port           1998;

  listen 80;
listen [::]:80;

  server_name fifumain.site www.fifumain.site;

  # Block Exploits
  include conf.d/include/block-exploits.conf;

  access_log /data/logs/proxy-host-2_access.log proxy;
  error_log /data/logs/proxy-host-2_error.log warn;

  map $scheme $hsts_header {
    https   "max-age=63072000; preload";
}

  location /api/v1/ {
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Scheme $scheme;
    proxy_set_header X-Forwarded-Proto  $scheme;
    proxy_set_header X-Forwarded-For    $remote_addr;
    proxy_set_header X-Real-IP          $remote_addr;
    proxy_pass       http://api:1998;


  # Block Exploits
  include conf.d/include/block-exploits.conf;

  }

  map $scheme $hsts_header {
    https   "max-age=63072000; preload";
}

  location /supersecretadmin {
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Scheme $scheme;
    proxy_set_header X-Forwarded-Proto  $scheme;
    proxy_set_header X-Forwarded-For    $remote_addr;
    proxy_set_header X-Real-IP          $remote_addr;
    proxy_pass       http://api:1998;

  # Block Exploits
  include conf.d/include/block-exploits.conf;
  }

  map $scheme $hsts_header {
    https   "max-age=63072000; preload";
}

  location / {
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Scheme $scheme;
    proxy_set_header X-Forwarded-Proto  $scheme;
    proxy_set_header X-Forwarded-For    $remote_addr;
    proxy_set_header X-Real-IP          $remote_addr;
    proxy_pass       http://api:1998;

  # Block Exploits
  include conf.d/include/block-exploits.conf;
  }

  # Custom
  include /data/nginx/custom/server_proxy[.]conf;
}

根据文档,我理解这些映射不属于服务器块内部,而是属于 http 块,但有两个问题 - 我没有这个块,如果我删除除第一个之外的所有映射,然后重新启动容器,它们仍然会重新出现在这个配置文件中,我无法创建 SSL 证书,也无法进一步使用 nginx 代理管理器。

答案1

您的配置中有四个指令实例map $scheme。一个位于server块外,其余位于server块内。

删除块中的那些server

相关内容