Reputation: 4693
I would like to configure nginx for different locations on / and I have the following config.
server {
listen 80;
server_name bla.com;
location = / { // on exact route match such as 'bla.com'
root /usr/share/nginx/html/folder; // it has index.html
}
location / { // rest all url such as bla.com/* are captured here eg. bla.com/temp/12
root /usr/share/nginx/html/dist; // different folder
}
}
How can I do this?
I also tried the below config with no luck -
server {
listen 80;
server_name bla.com;
root /usr/share/nginx/html;
location = / {
try_files $uri /folder/index.html; // it has index.html
}
location / { // rest all url such as bla.com/* are captured here eg. bla.com/temp/12
try_files $uri /dist/index.html; // different folder
}
}
Upvotes: 2
Views: 6970
Reputation: 336
You can achieve this by creating something like this:
server {
index index.html index.htm;
server_name test.example.com;
location / {
root /var/www/website1/public_html;
}
location /temp {
root /var/www/website2/public_html;
}
}
You can also do this with individual files like this:
location /robots.txt {
alias /var/www/website/public_html/robots.txt;
}
Upvotes: 2