Pavan K
Pavan K

Reputation: 4693

how to configure nginx for different paths

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

Answers (1)

notStan
notStan

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

Related Questions