NGINX: What is wrong with my nginx configuration NGINX: What is wrong with my nginx configuration nginx nginx

NGINX: What is wrong with my nginx configuration


try merging both server blocks:

 server{    listen 80 default_server;    listen [::]:80 default_server;    root /var/www/html;    # Add index.php to the list if you are using PHP    index index.html index.htm index.nginx-debian.html;    server_name _;    location / {        # First attempt to serve request as file, then        # as directory, then fall back to displaying a 404.        try_files $uri $uri/ /index.html ;    }    location /api/ {        proxy_pass http://127.0.0.1:8082/;        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;    }}

and access all the rest apis by appending '/api/' in the url.

May be its CORS issue, Add this in your location block:

  if ($request_method = 'OPTIONS') {        add_header 'Access-Control-Allow-Origin' '*';        add_header 'Access-Control-Allow-Credentials' 'true';        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';        # Custom headers and headers various browsers *should* be OK with but aren't        #        add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';        #        # Tell client that this pre-flight info is valid for 20 days        #        add_header 'Access-Control-Max-Age' 1728000;        add_header 'Content-Type' 'text/plain charset=UTF-8';        add_header 'Content-Length' 0;            return 204;  }