Welcome! Log In Create A New Profile

Advanced

How to set multiple directories in one link or it's just not possible?

Posted by Z-zzz 
How to set multiple directories in one link or it's just not possible?
May 17, 2023 01:33AM
Hi all!
How to set multiple directories in one or it's just not possible with use nginx?

Me need help with it:
There are server directories with subdirs and files on the server, for example:
/var/www/site1
/var/www/site2
/var/www/site3

How to configure nginx so that from these three directories all directories and files can be accessed from the same path - as an example, let the root of the site be http://example.com/
I tried like this:

server {
listen 80;
charset UTF-8;
server_name example.com;
index index.html index.php;

location / {
root "/var/www/tmp"; //empty dir
try_files $uri $uri/ @dir1 @dir2 @dir3;
autoindex on;
}

location @dir1 {
root "/var/www/site1";
try_files $uri $uri/;
}

location @dir2 {
root "/var/www/site2";
try_files $uri $uri/;
}

location @dir3 {
root "/var/www/site3";
try_files $uri $uri/ =404;
}

error_log /var/log/nginx/example.com-error.log;
access_log /var/log/nginx/example.com-access.log;
}
But nothing works :(

And tried this:
location / {
root "/var/www/site1";
try_files $uri $uri/ @dir2 @dir3;
autoindex on;
}

location @dir2 {
root "/var/www/site2";
try_files $uri $uri/;
}

location @dir3 {
root "/var/www/site3";
try_files $uri $uri/ =404;
}

See dirs and files only location "/var/www/site1", @dir2 and @dir3 dont visible in root link.

Thx.



Edited 1 time(s). Last edit at 05/17/2023 01:40AM by Z-zzz.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 90
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready