Reputation: 92
I have three static sites. I am using Vue 2 and running build for each folder.
I want to host all three static files on the same server instance. Right now I don't have domain so i want to host on server's IP itself.
I have folder in html/www folder
first_folder
second_folder
third_folder
All the above three folders have index.html file in it.
Let's say that I have an IP address 3.12.178.229
I want to access folders like
http://3.12.178.229 // i.e path for first_folder
http://3.12.178.229/second_path // i.e path for second_folder
http://3.12.178.229/third_path // i.e path for third_folder
I am able to access the index.html file which first_folder has, but when I am trying to access second_folder using IP http://3.12.178.229/second_folder It does not show anything.
{
listen 80;
server_name 3.12.178.229;
location / {
root path_to_first_folder/first_folder; // I am able to access this
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /second_path {
root path_to_first_folder/second_folder; // I am able to access this
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /third_path {
root path_to_first_folder/third_folder; // I am able to access this
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
Upvotes: 4
Views: 5872
Reputation: 49702
The pathname of the requested file is constructed by concatenating the value of root
directive with the URI. So you can only use root
with subfolders if (for example) second_path
and second_folder
is actually the same name. See this document for details.
For example:
location /foo {
root /path/to/root;
}
The URI /foo/index.html
is located at /path/to/root/foo/index.html
Where second_path
and second_folder
are different names, you will need to use the alias
directive. See this document for details.
For example:
location /foo {
alias /path/to/root/bar;
}
The URI /foo/index.html
is located at /path/to/root/bar/index.html
Upvotes: 2