2

I currently have a bunch of working static files at the domain name khairulslt.me (from NameCheap). Recently, I've tried setting up a subdirectory (khairulslt.me/RGBGame) as seen in the code below; However, I keep getting 404 errors. What am i missing out?

server {

  server_name khairulslt.me www.khairulslt.me;

  autoindex off;
  location / {
    root /var/www/khairulslt.me;
    index circles.html;
  }


listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/khairulslt.me/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/khairulslt.me/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

location /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 Certbot


if ($host = khairulslt.me) {
    return 301 https://$host$request_uri;
  } # managed by Certbot


listen 80;
server_name khairulslt.me www.khairulslt.me;
return 404; # managed by Certbot
}

I've tried all the different settings like (alias vs root), try_files, autoindex(on, off). My main website www.khairulslt.me works fine and is serving the html/css/js files in /var/www/khairulslt.me perfectly fine. I'm just not sure why I can't replicate the settings for my other app (html/css/js files in folder /RGBGame). Could it be that I've missed out something that isn't related to the nginx config?

womble
  • 95,029
  • 29
  • 173
  • 228
  • 1
    Unless the location of the files is under `/var/www/khairulslt.me/RGBGame/RGBGame` (last directory name twice), you should set the root to `root /var/www/khairulslt.me;` – Richard Smith Jun 10 '18 at 16:27
  • WOW!!! Thanks so much i was stuck at this for a week! Appreciate it alot man! May I know why I didnt need to specify the files as root /var/www/khairulslt.me/RGBGame even though that is where the files are located? – Khairul SIt Jun 10 '18 at 16:30
  • The subdirectory is already part of the URI (e.g. `/RGBGame/foo.html`). The path to the local file is constructed by concatenating the value of `root` with the URI. See [this link](http://nginx.org/en/docs/http/ngx_http_core_module.html#root) – Richard Smith Jun 10 '18 at 16:38

0 Answers0