Nginx 无法识别“用户”变量

Nginx 无法识别“用户”变量

我已经设置了一个开发服务器很长一段时间了,现在正在清理和设置一个新的开发服务器。

node.js我正在通过和运行一个前端和三个 API nginx。我以前从来没有遇到过这个问题nginx.conf,但由于某种原因,它现在无法正常工作。我还没有对它进行更改,也没有对sites/*.conf(s) 进行更改。它们在我的其他服务器上运行良好。

错误:

nginx: [emerg] unknown "user" variable
nginx: configuration file /etc/nginx/nginx.conf test failed

这是我的nginx.conf

user www-data;

## grep processor /proc/cpuinfo | wc -l
worker_processes auto;

pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
  ## ulimit -n
  worker_connections 1024;
  # multi_accept on;
}

http {
  ##
  ## Basic Settings
  ##
  sendfile on;
  tcp_nopush on;
  types_hash_max_size 2048;
  # server_tokens off;
  server_names_hash_bucket_size 64;
  # server_name_in_redirect off;
  include /etc/nginx/mime.types;
  default_type application/octet-stream;

  ##
  ## SSL Settings
  ##
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
  ssl_prefer_server_ciphers on;

  ##
  ## Logging Settings
  ##
  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;

  ##
  ## Gzip Settings
  ##
  gzip on;
  gzip_vary on;
  gzip_proxied any;
  gzip_comp_level 6;
  gzip_buffers 16 8k;
  gzip_http_version 1.1;
  gzip_min_length 256;
  gzip_types application/atom+xml application/geo+json application/javascript application/x-javascript application/json application/ld+json application/manifest+json application/rdf+xml application/rss+xml application/xhtml+xml application/xml font/eot font/otf font/ttf image/svg+xml text/css text/javascript text/plain text/xml;

  ##
  ## Virtual Host Configs
  ##
  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites/*;
}

这些是sites/*.conf我所拥有的 2 个:

1.conf(API)

server {
  ## HTTPS
  listen 443 ssl;
  listen [::]:443 ssl;

  ## TIMEOUTS
  proxy_read_timeout 600;
  proxy_connect_timeout 600;
  proxy_send_timeout 600;

  ## SSL CONFIGURATION
  ssl_certificate /etc/ssl/XXXX.pem;
  ssl_certificate_key /etc/XXXX.key;
  ssl_client_certificate /etc/ssl/cloudflare.crt;
  ssl_verify_client on;

  ## LISTEN FOR THESE HOSTNAMES
  server_name XXXX.XXXX.XXXX;

  ## HEADERS
  add_header Cache-Control no-cache;

  ## CONTENT LOCATION
  location /XXXX1/ {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_pass http://localhost:3001/;
    proxy_redirect off;
  }

  location /XXXX2/ {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_pass http://localhost:3002/;
    proxy_redirect off;
  }

  location /XXXX3/ {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_pass http://localhost:3003/;
    proxy_redirect off;
  }

  ## ERROR PAGE LOCATION
  error_page 404 /404.html;
  location = /404.html {
    root $HOME/XXXX/error/404;
    internal;
  }

  ## DENY REQUESTS STARTING WITH ht (htaccess, htgroup, htusers)
  location ~ /\.ht {
    deny all;
  }
}

2.conf(前端)

server {
  ## HTTPS
  listen 443 ssl;
  listen [::]:443 ssl;

  ## TIMEOUTS
  proxy_read_timeout 600;
  proxy_connect_timeout 600;
  proxy_send_timeout 600;

  ## SSL CONFIGURATION
  ssl_certificate /etc/ssl/XXXX.pem;
  ssl_certificate_key /etc/ssl/XXXX.key;
  ssl_client_certificate /etc/ssl/cloudflare.crt;
  ssl_verify_client on;

  ## LISTEN FOR THESE HOSTNAMES
  server_name XXXX.XXXX.XXXX;

  ## HEADERS
  add_header Cache-Control no-cache;

  ## CONTENT LOCATION
  location / {
    expires -1;
    root $HOME/XXXX/XXXX;
    index index.html;
    try_files $uri $uri/ =404;
  }

  ## ERROR PAGE LOCATION
  error_page 404 /404.html;
  location = /404.html {
    root $HOME/XXXX/error/404;
    internal;
  }

  ## DENY REQUESTS STARTING WITH ht (htaccess, htgroup, htusers)
  location ~ /\.ht {
    deny all;
  }
}

答案1

我通过逐渐删除来解决这个问题.confs

答案很简单,我不会再犯同样的错误……

不能ENV在 nginx 中使用变量.conf...

相关内容