Score:0

Nginx not recognising "user" variable

vn flag

I have had a dev server set up for quite some time and am in the process of cleaning and setting up a new one.

I am running a frontend and three APIs via node.js and nginx. I have never had a problem with this nginx.conf before but for some reason it is now not working. I have not made changes to it yet nor have I made changes to the sites/*.conf(s) either. They were running fine on my other server.

The error:

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

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

These are the 2 sites/*.conf(s) that I have:

1.conf (the apis)

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 (the frontend)

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;
  }
}
Score:0
vn flag

I figured it out by gradually deleting .confs.

The answer is very simple, and I won't make the mistake again...

You CANNOT use ENV variables in a nginx .conf...

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.