1

I can't figure out the NGINX config to launch the site.

I can’t figure it out myself, all the same, there is not enough theoretical basis. Maybe you can advise.

env BACKEND_API;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
worker_processes 4;
events {
   worker_connections  1024;
}
   http {
      include mime.types;
      default_type application/octet-stream;
      upstream backend {
         server backend;
      }
   server {
       set_by_lua $backend_url 'return os.getenv("BACKEND_API")';
       listen 80;
       server_name _;
       server_tokens off;
       client_max_body_size 100M; 

       location / {
           root   /www/html;
           index  index.html index.htm;
           try_files $uri $uri/ /index.html;
       }

       location /api {
           try_files $uri @proxy_api;
       }

       location @proxy_api {
           proxy_set_header X-Forwarded-Proto https;
           proxy_set_header X-Url-Scheme $scheme;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header Host $http_host;
           proxy_redirect off;
           proxy_pass $backend_url;   
       } 
   }
  }

I get an error:

frontend        | 2022/02/21 08:29:58 [error] 28#28: *2 no resolver defined to resolve backend, client: 31.176.83.92, server: _, request: "POST /api/auth HTTP/1.1", host: "194.86.154.183", referrer: "http://194.86.154.183/"

Can you please tell me where to look? Any advice and help is welcome.

freeholod
  • 11
  • 2

1 Answers1

1

In your http block the below config:

upstream backend {
     server backend;
  }

is throwing the error as it is not able to resolve the server value as backend.

here is a basic uses of upstream module from docs

upstream backend {
    server backend1.example.com       weight=5;
    server backend2.example.com:8080;
    server unix:/tmp/backend3;
    
    server backup1.example.com:8080   backup;
    server backup2.example.com:8080   backup;
}

server {
    location / {
        proxy_pass http://backend;
    }
}
  • Also you don't need the upstream module if you have just one server where proxy_pass is enough, it is used for cases like load balancer and all. – Nasir Rabbani Feb 21 '22 at 09:37