将Yii2从Apache迁移到Nginx-在后端应用程序上失败 [英] Migrating Yii2 from Apache to Nginx - failed on backend app
问题描述
我尝试将Yii2应用程序从使用apache迁移到nginx.我在单个域上使用Yii2高级模板,所以我遵循
I try to move my Yii2 app from using apache to nginx. I'm using Yii2 advanced template on a single domain, so I follow the solution from this link creating a symlink from frontend/web
to the backend/web
. This solution works fine when I'm using apache, but when I try to use nginx I can't open the backend app.
前端应用程序工作正常,但是当我尝试使用app.local/belakang
打开后端应用程序时,它被重定向到app.local/belakang/site/login
,但仍然停留在前端应用程序中,因此给出了[yii\web\HttpException:404] exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "belakang/site/login".'
The frontend app works fine, but when I try to open the backend app using app.local/belakang
, it is redirected to app.local/belakang/site/login
, but still stuck in the frontend app and therefore giving a [yii\web\HttpException:404] exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "belakang/site/login".'
这是我在frontend/web
目录上的符号链接:
Here is the symlinks that I have on the frontend/web
directory :
lrwxrwxrwx 1 vagrant vagrant 17 Jun 24 14:03 belakang -> ../../backend/web
这是我使用的nginx vhost配置:
and this is the nginx vhost config that I use:
server {
charset utf-8;
client_max_body_size 128M;
listen 80; ## listen for ipv4
server_name app.local;
root /var/www/html/frontend/web;
index index.php;
location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php$is_args$args;
}
# deny accessing php files for the /assets directory
location ~ ^/assets/.*\.php$ {
deny all;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
try_files $uri =404;
}
location ~* /\. {
deny all;
}
}
任何人都可以帮忙,以便我可以从app.local/belakang
打开后端应用程序吗?
Can anyone help so that I can open the backend app from app.local/belakang
?
推荐答案
在下面添加配置即可自行修复
Fix it myself by adding config below
location ^~ /belakang {
try_files $uri $uri/ /belakang/index.php$is_args$args;
location ~ /\.(ht|svn|git) {
deny all;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php/php5-fpm.sock;
try_files $uri =404;
}
}
这篇关于将Yii2从Apache迁移到Nginx-在后端应用程序上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!