如何在nginx.conf中設定“set”?

如何在nginx.conf中設定“set”?

我有一個 nginx.conf:

worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
    worker_connections 1024;
}
http {
    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;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    server {
      listen 80 default_server;
      listen [::]:80 default_server ipv6only=on;
      server_name localhost;
      resolver 172.31.0.2;
      set $proxy_pass_url https://my-url.com;

      # redirect /kibana
      location = /kibana {
          rewrite ^ /_plugin/kibana redirect;
      }

      location / {
          proxy_pass $proxy_pass_url;
          auth_basic "Username and Password are required";
          auth_basic_user_file /etc/nginx/.htpasswd;

          proxy_set_header Authorization "";
          proxy_hide_header Authorization;

      }
      include /etc/nginx/conf.d/*.conf;
  }
}

我嘗試設定一個proxy_pass_url稍後在conf文件中使用它。解釋了我為什麼使用該套件這裡

但我不斷得到:

invalid number of arguments in "set" directive in /etc/nginx/nginx.conf

我究竟做錯了什麼?如何在 nginx 中設定變數?我也嘗試過set $proxy_pass_url "https://my-url.com";

相關內容