Nginx无法识别“user”变量

j9per5c4  于 2022-11-28  发布在  Nginx
关注(0)|答案(1)|浏览(256)

我已经有一个开发服务器设置了相当一段时间,并在清理和设置一个新的过程中。
我正在通过node.jsnginx运行一个前端和三个API。我以前从来没有遇到过这个nginx.conf的问题,但由于某种原因,它现在不工作了。我还没有对它做任何修改,也没有对sites/*.conf做任何修改。它们在我的另一个服务器上运行得很好。
错误:

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/*;
}

这是我拥有的2个sites/*.conf
1.配置(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;
  }
}
  1. 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;
  }
}
gijlo24d

gijlo24d1#

我发现你不能在nginx配置中使用环境变量。
必须移除所有$HOME声明。

相关问题