I have configured the NGINX server configuration for the location of the application but I am getting the index.html data with 200 status instead of the original API response.
The server configuration on the NGINX side is as follows:
server {
listen 443 default_server;
listen [::]:443 default_server;
ssl on;
server_name abc.global;
root /var/www/html/build;
location / {
try_files $uri $uri/ /index.html;
}
location = /50x.html {
alias /var/www/html/build;
}
error_page 404 /404.html;
error_page 403 /403.html;
# To allow POST on static pages
error_page 405 =200 $uri;
ssl_certificate /Path/abc.crt;
ssl_certificate_key /Path/abc.key;
Can anyone please guide me, Whats the issue in the server configuration that I am getting this issue?
2
Answers
proxy_pass
An api needs a different settings compared with static web. You need to use proxy_pass. Check:
tips
/api/auth
. This will help you to have an easy nginx configchange your
NGINX config
to following:explanation:
/api/
block is designed to forward any API requests (e.g., /api/users) to your backend API server running onhttp://localhost:3000
(you can change this based on where your API is hosted)./
block will continue serving static files (like index.html) for non-API requests, making it suitable for single-page applications (SPAs)./api/
or adjust the location block accordingly.If your API path is different (e.g.,/v1/api
or something else), you will need to adjust the location directive to match your API routes.