NGINX subdirectories using alias
$ sudo apt-get update
$ sudo apt-get install nginx -y
config sites-available
server {
listen 80;
listen [::]:80;
server_name _;
root /var/www/html;
access_log /etc/nginx/sites-available/log/access.log;
error_log /etc/nginx/sites-available/log/error.log;
location /app1/ {
alias /var/www/html/app1/;
}
location /app2/ {
alias /var/www/html/app2/;
}
}
test & restart nginx
sudo nginx -t
sudo nginx -s reload
PHP-fpm
....
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}
...
server {
listen 80;
listen [::]:80;
server_name _;
root /var/www/html;
access_log /etc/nginx/sites-available/log/access.log;
error_log /etc/nginx/sites-available/log/error.log;
location /app1/ {
alias /var/www/html/app1/;
index index.php; # new
}
location /app2/ {
alias /var/www/html/app2/;
index index.php; # new
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}
}
test & restart nginx
sudo nginx -t
sudo nginx -s reload