Есть два сайта - site1 и site2, которые лежат в директориях /var/www/site1 и /var/www/site2 соответственно. Необходимо, что бы по запросу http://localhost/ открывался site1, а при запросе http://localhost/site2 открывался site2.
/etc/nginx/sites-available/site1
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
set $base /var/www/site1;
root $base/;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:var/run/php/php7.4-fpm.sock;
}
}
/etc/nginx/sites-available/site2
server {
listen 80;
listen [::]:80;
server_name localhost/site2;
set $base /var/www/site2;
root $base/;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:var/run/php/php7.4-fpm.sock;
}
}
На данный момент открывается только site1, а при обращении к http://localhost/site2 выдаёт:
404 Not Found nginx/1.18.0 (Ubuntu)
Как настроить nginx так, что бы по запросу http://localhost/ открывался site1, а при запросе http://localhost/site2 открывался site2?
localhost
, то и секцияserver
тоже должна быть ровно одна, а уже внутри неё сделать дваlocation /
иlocation /site2