I’m trying to serve a folder that contains HTML, JS, PHP, Java, and a couple of other different file types with Ngnix. I plan to then import two JS files from that folder into my index.html like so :
JavaScript
x
3
1
<script src="/scripts/jmol/jsmol/JSmol.min.js"></script>
2
<script src="/scripts/jmol/jsmol/js/Jmol2.js"></script>
3
The problem is, I am getting a 404 Not Found error :
JavaScript
1
4
1
nginx_1 | 172.18.0.1 - - [14/Jan/2021:00:39:01 +0000] "GET /scripts/jmol/jsmol/JSmol.min.js HTTP/1.1" 404 162 "http://localhost/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
2
nginx_1 | 172.18.0.1 - - [14/Jan/2021:00:39:01 +0000] "GET /scripts/jmol/jsmol/js/Jmol2.js HTTP/1.1" 404 161 "http://localhost/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
3
4
Below is my nginx.conf
file.
JavaScript
1
37
37
1
worker_processes 2;
2
3
events { worker_connections 1024; }
4
5
http {
6
server {
7
listen 80;
8
proxy_buffering ${BUFFERING};
9
server_name my.domain.org;
10
location /__webpack_hmr {
11
proxy_pass http://vue:8080;
12
proxy_http_version 1.1;
13
proxy_set_header Upgrade $http_upgrade;
14
proxy_set_header Connection “upgrade”;
15
}
16
location /scripts/ {
17
alias "/home/user/frontend/src/assets/js";
18
19
}
20
location / {
21
try_files $uri $uri/ @proxy_to_frontend;
22
proxy_pass http://vue:8080;
23
}
24
location /api {
25
proxy_pass http://django:8082;
26
}
27
location @proxy_to_frontend {
28
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
29
proxy_set_header Host $http_host;
30
proxy_redirect off;
31
proxy_pass http://vue:8080;
32
}
33
}
34
35
}
36
37
Any help would be appreciated.
Advertisement
Answer
I figured out my problem. I failed to mention that I am using Docker as well and had to first move my desired files to /usr/share/nginx/html/
within the Nginx docker container and then put that file location as the location for alias
.