Настройка nginx alias для подкаталога virtualhost

Категория: Nginx

Настройка alias для подкаталога nginx virtualhost.

server {
    listen      80;
    server_name some.domain.net;
    root        /var/www/some.domain.net/;
    index       index.html index.php;
    
    location / {
        root /var/www/some.domain.net/front/;
        autoindex off;
        try_files $uri $uri/ =404;
    }

    location /backend {
        alias /var/www/some.domain.net/backend/public;
        try_files $uri $uri/ @backend;
        
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        }
    }
    
    location @backend {
        rewrite /backend/(.*)$ /backend/index.php?/$1 last;
    }
    
    location ~ \.php$ {
        include      snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }
    
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
    location ~ /\.ht { deny all; }
}

Источник: https://serversforhackers.com/c/nginx-php-in-subdirectory

#nginx alias sub directory, #nginx subdirectory alias

категория: Nginx