Issue
For some reason, my nginx server doesn't seem to be finding the location of few javascript files required for my angular code. It is still able to find few of them that are on the same location. The 2 javascript codes that angular doesn't seem to be able to identify are,
main-es2015.f342ce8f66110b6402ac.js, runtime-es2015.5798a1d137c7e59283fe.js
Below is the code inside my nginx configuration file,
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri /index.html;
add_header 'Access-Control-Allow-Origin' '*';
}
The base path in my index.html is as below,
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Admin Portal</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/png" href="favicon.png">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<ngx-app>Loading...</ngx-app>
After deploying the application using docker container, i can see the files inside inside /usr/share/nginx/html as expected,
Screen print from docker container
As shown in above screen print all my js files are in the location it is supposed to be. But while nginx serves the index.html it is unable to find the location of the 2 JS files and returns back index.html again. What is surprising is, it is correctly serving the other 2 JS files that are again in the same location,
polyfills-es2015.2a005ad49cdc9f23d0cf.js, scripts.9be41abd9653638cc717.js
Solution
After breaking my head for a while i was able to solve this issue. The issue eventually was not due to nginx configuration and it looks perfect. The issue was with my AWS load balancer that is one layer above the nginx server. The load balancer was basically not routing the requests when the client was requesting for javascript file. Instead it was routing it to an incorrect target group. So i added a condition for the same in my AWS Load balancer and it worked perfectly fine.
Answered By - Veerakumar Kesavan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.