Php 部署Yii2高级模板的Nginx配置
我是使用Nginx的新手,我有一个使用Yii2开发的高级应用程序。我当时正在使用apache server,我的VirtualHost有以下配置:Php 部署Yii2高级模板的Nginx配置,php,nginx,yii2,Php,Nginx,Yii2,我是使用Nginx的新手,我有一个使用Yii2开发的高级应用程序。我当时正在使用apache server,我的VirtualHost有以下配置: <VirtualHost *:80> DocumentRoot "path/to/cosmox/frontend/web" ServerName cosmox.com ServerAlias www.cosmox.com Alias /admin path/to/cosmox/backend/web Alia
<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
所有要下载的新闻海报、游戏海报或文件都可以在backend/web/uploads文件夹中找到,而且服务很好。我的问题是后端和api应用程序
我试过推荐的帖子,比如和其他帖子,但它们对我不起作用
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;
} }