Score:0

NGINX: configure multiple locations to different directories

us flag

I want to define a separate directory for each part of my website on my NGINX server.

domain.com/                     -->     /var/www/html/domain.com/website
domain.com/blog/                -->     /var/www/html/domain.com/blog
domain.com/checkout/            -->     /var/www/html/domain.com/checkout
domain.com/download/            -->     /var/www/html/domain.com/download
domain.com/forum/               -->     /var/www/html/domain.com/forum

The different configurations I've tried don't work, I get 404 errors.

server {
    location /  {
        root /var/www/html/domain.com/website;
    }
    
    location /blog  {
        root /var/www/html/domain.com/blog;
    }
}

or

server {
    root /var/www/html/domain.com/website;
    
    location /blog  {
        root /var/www/html/domain.com/blog;
    }
}

or

server {
    root /var/www/html/domain.com/website;
    
    location /blog/  {
        alias /var/www/html/domain.com/blog;
    }
}

or

server {
    root /var/www/html/domain.com/website;
    
    location /blog/  {
        alias /var/www/html/domain.com/blog/;
    }
}

or

server {
    root /var/www/html/domain.com;
    
    location /  {
        alias /var/www/html/domain.com/website/;
    }
    
    location /blog/  {
        alias /var/www/html/domain.com/blog/;
    }
}

or

server {
    location ~ ^/(?!(blog|checkout|download|forum))/ { 
        root /var/www/html/domain.com/website;
    } 
    
    location /blog/  {
        root /var/www/html/domain.com/blog;
    }
}
Score:0
us flag

This configuration solved my problem

server {
    location / { 
        root /var/www/html/domain.com/website;
    } 
    
    location ~ ^/(?!(blog|checkout|download|forum))/ { 
        root /var/www/html/domain.com/website;
    } 
    
    location /blog/  {
        alias /var/www/html/domain.com/blog/;
    }
}
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.