Score:0

nginx try_files and multiple location blocks

us flag

I have 2 domains, each with its own document root. The root of one domain contains the folders pics and docs that I want accessible through the other domain. So domain1.com/pics/house.jpg and domain2.com/pics/house.jpg would show the same image.

Below is an excerpt from the config file for domain2. It doesn't work - I always get a 404 when accesing the image in domain1 root on domain2. I'd welcome any suggestions on how to rewrite this to fix it. Thank you

root /home/admin/domain2.com/html;

index index.php index.html;

location /pics/ {
       root /home/admin/domain1.com;
}

location /docs/ {
       root /home/admin/domain1.com;
}

location / {
        try_files $uri $uri/ =404;
}

location ~ \.php$ {
       include snippets/fastcgi-php.conf;
       fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
sv flag
Please post the full config. It looks like root of domain1.com is `/home/admin/domain1.com/html` and `pics` folder is at `/home/admin/domain1.com/html/pics`. Anyway, most such issues can be resolved by creating a symlink, rather than re-configuring Nginx.
Score:0
us flag

Turns out, my code didn't work for cases where /pics/ contained further folders. Using the following worked.

location ^~ /pics/ {
       root /home/admin/domain1.com;
       # Queries beginning with /pics/ and then stops searching.
}
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.