5

I have some static html files under:

/var/www/project1 

Nginx config for this project is:

server_name             www.project1.com project1.com;
root                    /var/www/project1;

location / {
    index           index.html;
}

My goal is to use nginx so that when a user enters this url:

www.project1.com/project2

Nginx uses another root, I have tried:

 location /project2 {
     root /var/www/project2;
     index index.html;
}

But this is not working. Any idea on how to achieve this?

Milos Cuculovic
  • 19,631
  • 51
  • 159
  • 265
  • 1
    what is your actual path for project2? Is it ``/var/log/project2``? You should use ``root /var/www`` in your location for project2 or you will be looking for files under ``/var/www/project2/project2`` – Hammer May 27 '16 at 10:38
  • @Lution, thx, that fixed the issue. In fact, the path of project2 is `/var/www/project2`. Could you please answer this and I'll accept – Milos Cuculovic May 27 '16 at 10:42

1 Answers1

6

According to your config of project2

location /project2 {
    root /var/www/project2;
    index index.html;
}

Nginx will be looking for files under the path /var/www/project2/project2/ for your requests to project2. So if your project2 is under /var/www/project2, The correct config should be

location /project2 {
    root /var/www;
    index index.html;
}

Another alternative is to use alias instead of root.

in your case is alias /var/www/project2, check here

Hammer
  • 1,514
  • 2
  • 14
  • 22