I've configured a Yii2 advanced template site (advanced meaning 2 sites: first is frontend site and the second is the admin area)
My frontend (Nginx's root) is at /public_html and my admin is at /public_html/admin.
Almost everything works with the exception of two endpoints that were developed in a "different way".
I think this is were my problem resides: Usually any request will point to www.mysite.com/<controller_name>/index and the index.php file will take the request, and let PHP decide what to do given the application routes.
Unfortunately I have two endpoints (one in frontend and another in admin) that are www.mysite.com/<controller_name>/action (mind index was replaced by action). So now Nginx is routing that request to index but should be pointing it to action. Or at least this is how I see it. Amiright?
Here's what I mean:
regular frontend routes
- Request URL: www.mysite.com/index
- all route to public_html/index.php but served by Nginx
location /
regular admin routes
- Request URL: www.mysite.com/admin/index
- all route to public_html/admin/index.php but served by Nginx
location /admin
non-regular frontend route:
- Request URL: www.mysite.com/not_index <== I think this is my problem
- route to public_html/index.php still served by Nginx
location /
<== I think this is my problem
non-regular backend route:
- Request URL: www.mysite.com/admin/not_index <== I think this is my problem
- route to public_html/admin//index.php still served by Nginx
location /admin
<== I think this is my problem
"Obviously" my two non-regular routes are resolving to 404 not found. And I'm not able to find a solution for this. I've been at it for several days now...
Here's my nginx.conf:
server {
listen 80;
listen [::]:80 default_server ipv6only=on;
root /var/www/mysite/public_html;
index index.php index.html index.htm;
server_name localhost;
location /admin {
root /var/www/mysite/public_html/admin;
index index.php;
try_files $uri /admin/index.php$is_args$args ;
location = /admin/ {
return 301 /admin;
}
location = /admin/frontend-users/search-influencers {
try_files /admin/$uri /admin/$uri.php;
}
}
location / {
root /var/www/mysite/public_html;
try_files $uri /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_intercept_errors on;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* \.(css|map|mp3|mp4|js|jpg|jpeg|png|gif|bmp|ico|mov|swf|pdf|zip|rar)$ {
access_log off;
log_not_found on;
try_files $uri /public_html/$uri =404;
}
}
What am I doing wrong?