Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple projects in folders Nginx

Tags:

nginx

I'm trying to configure nginx to handle different projects inside a folder.

I have the foler "www" which has a lot of subfolders, each one of them being an independent project, in which the .html and other files have relative routes to the files in the project.

For example if you go to www.example.com/project1 I want the index.html file located in www/project1/index.html to be served. project2 should serve www/project2/index.html and so on. The problem is that each on of this html files have relatives routes to images and subfolders of the projects and the problem is that I don't know how to handle that in Nginx.

Also when visiting www.example.com/ a different folder should be served, for example www/main/index.html (also with relative routes).

How can I achieve this properly in Nginx? I have been reading documentation and I can serve the .html properly but the images and relative paths are all 404.

Thank you

like image 316
Gonzalo Hernandez Avatar asked May 07 '26 03:05

Gonzalo Hernandez


1 Answers

You may want to configure a location per project like this

location /project1 {
    root /<yourPath>/www/project1;
    index index.html;
}
location /project2 {
    root /<yourPath>/www/project2;
    index index.html;
}

Respective docs:

http://nginx.org/en/docs/http/ngx_http_core_module.html#location

http://nginx.org/en/docs/http/ngx_http_core_module.html#root

http://nginx.org/en/docs/http/ngx_http_index_module.html#index

like image 85
wick Avatar answered May 09 '26 18:05

wick