Как правильно настроить nginx под yii2?

Добрый день всем, помогите разобраться почему backend не работает под ссылкой site.ru/admin.
При переходе на ссылку 193.200.74.52/admin ловлю 404 ошибку и проект продолжает смотреть в frontend/web
Я с nginx только учусь работать поэтому камнями не кидайте. Вот конфиг nginx
server {

    #client_max_body_size 200M;

    listen 80 default_server;
    listen [::]:80 default_server;

    server_name 193.200.74.52;
    root /var/www/notice.com/frontend/web;
   
    index index.php;

    charset utf-8;
    
    location / {
        root /var/www/notice.com/frontend/web;
        try_files $uri $uri/ /index.php$is_args$args;
        
        rewrite ^/(.*)/$ /$1 permanent;
        
        location ~ ^/assets/.+\.php(/|$) {
            deny all;
        }
    }
    
    location /admin {
        root /var/www/notice.com/backend/web;
        try_files $uri $uri/ /index.php$is_args$args;
        
        rewrite ^/(.*)/$ /$1 permanent;
        
        location ~ ^/assets/.+\.php(/|$) {
            deny all;
        }
    }
    
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }
    
    #location ~ /\.ht {
    #    deny all;
    #}
}
  • Вопрос задан
  • 7700 просмотров
Решения вопроса 1
@Mysterion
server {
    listen 80 default_server;
    server_name notice.com;

    set $base_root /var/www/notice.com;
    root $base_root;

    charset UTF-8;
    index index.php index.html;

    location / {
        root $base_root/frontend/web;
        try_files $uri $uri/ /frontend/web/index.php$is_args$args;

        location ~ ^/assets/.+\.php(/|$) {
            deny all;
        }
    }

    location /admin {
        alias $base_root/backend/web/;

        try_files $uri /backend/web/index.php$is_args$args;

        location ~ ^/admin/assets/.+\.php(/|$) {
            deny all;
        }
    }

    location ~ ^/.+\.php(/|$) {
        rewrite (?!^/((frontend|backend)/web|admin))^ /frontend/web$uri break;
        rewrite (?!^/backend/web)^/admin(/.+)$ /backend/web$1 break;

        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }

    location ~ /\. {
        deny all;
    }
}
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
slo_nik
@slo_nik Куратор тега Yii
Добрый день.
Тут найдёте пример настройки Nginx
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы