Using Nginx to serve a static files in a subdirectory
Solved it.Needed to change this block of code here:
location /RGBGame {root /var/www/khairulslt.me;index colorGame.html;try_files $uri $uri/ /var/www/RGBGame/colorGame.html?q=$uri&$args;autoindex off;}
Will leave my final configuration here in case it helps anyone:
server { server_name khairulslt.me www.khairulslt.me; autoindex off; location / { root /var/www/khairulslt.me; index circles.html; }listen 443 ssl; # managed by Certbotssl_certificate /etc/letsencrypt/live/khairulslt.me/fullchain.pem; # managed by Certbotssl_certificate_key /etc/letsencrypt/live/khairulslt.me/privkey.pem; # managed by Certbotinclude /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbotssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbotlocation /RGBGame { root /var/www/khairulslt.me/RGBGame; index colorGame.html; try_files $uri $uri/ /var/www/RGBGame/colorGame.html?q=$uri&$args; autoindex off; }location /robots.txt { return 200 "User-agent: *\nDisallow: /\n"; }} server {if ($host = www.khairulslt.me) { return 301 https://$host$request_uri; } # managed by Certbotif ($host = khairulslt.me) { return 301 https://$host$request_uri; } # managed by Certbotlisten 80;server_name khairulslt.me www.khairulslt.me;return 404; # managed by Certbot}
What this config does:
1) Serve static files, Web App #1, aka bunch of html/css/js files) at the URL khairulslt.me
2) Serve second set of static files, Web App #2, aka bunch of html/css/js files) at the URL khairulslt.me/RGBGame
You don't need to provide a path to the file, but to the directory in your alias directive.
So simply use:
location /RGBGame/ { alias /var/www/RGBGame/; index colorGame.html; }
You alias seems to be pointing to a file colorGame.html
give a try to this:
server { listen 80; server_name khairulslt.me www.khairulslt.me; location /RGBGame/ { alias /var/www/RGBGame/; }}
When using alias
a request to ://khairulslt.me/RGBGame/file.foo
will serve files from:
/var/www/RGBGame/file.foo
You could use root
for example (append the location to the path):
location /RGBGame/ { root /var/www/khairulslt.me/; }
In this case, requests to ://khairulslt.me/RGBGame/file.foo
will serve files from:
/var/www/khairulslt.me/RGBGame/file.foo