I am new using Nginx and a have an advanced app developed using Yii2. I was working with apache server and I had this configuration for my VirtualHost:
<VirtualHost *:80>
DocumentRoot "path/to/cosmox/frontend/web"
ServerName cosmox.com
ServerAlias www.cosmox.com
Alias /admin path/to/cosmox/backend/web
Alias /uploads path/to/cosmox/backend/web/uploads
Alias /api path/to/cosmox/api/web
ErrorLog "logs/cosmox-error.log"
CustomLog "logs/cosmox-access.log" common
Options +FollowSymLinks
But the hosting server at work has no apache server included, they only have Nginx, so I have built an Nginx configuration but, I can only see the frontend app. When I access /admin it runs the index.php file and redirects to login page but 404 not found
is my server response. This is my Nginx conf:
server {
listen 80;
#listen [::]:80;
index index.php;
error_log /var/log/nginx/cosmox.errors.log;
access_log /var/log/nginx/cosmox.access.log combined;
server_name cosmox.com www.cosmox.com;
#root /path/to/cosmox/backend/web;
location / {
root /path/to/cosmox/frontend/web;
index index.php;
try_files $uri /index.php$is_args$args;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
location /admin {
alias /path/to/cosmox/backend/web;
index index.php;
#try_files $uri /index.php$is_args$args; //This entry break the backend redirect
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; //this entry such throw a "File not found" text
}
}
location /api {
alias /path/to/cosmox/api/web;
index index.php;
#try_files $uri /index.php$is_args$args;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
location /uploads {
alias /path/to/cosmox/backend/web/uploads;
try_files $uri $uri;
}
location = /favicon.ico {
try_files /favicon.ico =204;
} }
All resources news posters, games posters or files to download are available on backend/web/uploads folder, and it is well served. My problem is with backend and api app.
I tried recommended posts like Yii2 nginx conf and mickgeek/yii2-advanced-one-domain-config and others but they are not working for me.