Access simple node.js app subdirs with nginx

0

I have a Ubuntu server with nginx installed on it and run a simple node.js app on port 3000.

I managed to configure nginx to serve me the app on /.

My structure looks like this:

mainFolder
  app.js etc...
  ------------->folder1
                  index.html
                  ----------->folder2
                                index.html

Now when accessing my servers IP in browser i get the index.html from folder1: this is correct.

But when i try to access myIp/folder2/index.html I get : 404 Not Found

Nginx config:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    location / {
            proxy_pass http://localhost:3000;
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
            auth_basic "Restricted";
            auth_basic_user_file /etc/nginx/.htpasswd;
    }

Could somebody explain what I'm doing wrong here pls?

Help would be greatly appreciated.

Olivier Krull

Posted 2016-07-12T08:01:15.640

Reputation: 121

Answers

0

From the file tree you provided, I understand folder2is located in folder1. That means to acces folder2/index.html, the full URL you should use is: 127.0.0.1/folder1/folder2/index.html replacing the IP by whatever is your IP/domain name.

If you want to access it with 127.0.0.1/folder2/index.html you need to put folder2in the same folder as folder1.

Nathan.Eilisha Shiraini

Posted 2016-07-12T08:01:15.640

Reputation: 2 503

Thy for your answer but I just managed to get it work. I just commented out: try_files $uri $uri/ =404; – Olivier Krull – 2016-07-12T08:40:15.893