3

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

server {
  listen 80;

  index circles.html;
  server_name khairulslt.me www.khairulslt.me;

  location / {
  root /var/www/khairulslt.me;
  add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy- 
  revalidate, max-age=0';
  expires off;
  }

  location /RGBGame {
  alias /var/www/RGBGame/colorGame.html;
  index colorGame.html;
  }
}

PS: I want to serve the new files as a working web app under the same Digital Ocean droplet that I'm using for the circles app.

2
  • Check your access.log and you will see where your request is going in file system Commented Jun 7, 2018 at 5:03
  • 59.189.202.117 - - [07/Jun/2018:13:39:06 +0800] "GET /RGBGame HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36" Yeah I got that, not sure where to start with that though unfortunately Commented Jun 7, 2018 at 5:41

3 Answers 3

4

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 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
}

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

Sign up to request clarification or add additional context in comments.

Comments

1

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; 
}

2 Comments

Have tried that but still returns error 404 : | Do u know if there are any other instructions i need to perform to set up a subdirectory? Like using Express to set a route or something? Completely new to this sorry for the newbie questions!
Make sure you are editting the right file. Do you have ssl?? Try checking "/sites-available/default" this may be where you need to edit.
1

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

3 Comments

thanks! have tried both alias and root variants and still 404; I Also cant remove index circles.html; in the 3rd line, otherwise khairulslt.me will not load in the browser
@sgeza do you have files (images) on the defined paths?
yeap i do, css/js/html files on the defined paths, i never had to define "running them on my main khairulslt.me to get that one working though

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.