Answer the question
In order to leave comments, you need to log in
How to configure a redirect to another part of an advanced Yii2 application in nginx?
Hello. There is an Advanced Yii2 application that has: backend, frontend, api.
Under the backend, frontend, it was possible to create redirects, but something doesn’t work under the API.
The API follows the link: site.zone/api/web, I would like to achieve a link like site.zone/api
Working configurations for frontend/backend:
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?$args;
location = /admin/ {
return 301 /admin;
}
location ~* ^/admin/(.+\.php)$ {
try_files $uri /backend/web/$1?$args;
}
}
location ~ [^/]\.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
rewrite (?!^/((frontend|backend)/web|admin))^ /frontend/web$uri break;
rewrite (?!^/backend/web)^/admin(/.+)$ /backend/web$1 break;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
location ~ /\. {
deny all;
}
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?$args;
location = /admin/ {
return 301 /admin;
}
location ~* ^/admin/(.+\.php)$ {
try_files $uri /backend/web/$1?$args;
}
}
location /api {
alias $base_root/api/web;
try_files $uri /api/web/index.php?$args;
location = /api/ {
return 301 /api;
}
location ~* ^/api/(.+\.php)$ {
try_files $uri /api/web/$1?$args;
}
}
location ~ [^/]\.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
rewrite (?!^/((frontend|backend)/web|admin))^ /frontend/web$uri break;
rewrite (?!^/backend/web)^/admin(/.+)$ /backend/web$1 break;
rewrite (?!^/api) /api/web$1 break;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
location ~ /\. {
deny all;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question