在yii2上访问模块时找不到Nginx 404

时间:2018-12-02 00:41:13

标签: php yii2 nginx-config

我有使用yii2和nginx的项目API,我的文件夹结构是:

root
-- modules
----v1
------- controllers
----------- RefCityController.php
------- models
------- views

在web.php上设置

'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'rules' => [
    ],
],

在nginx上,我将文件夹API应用的结构为/var/www/html/api

我的根文件夹/var/www/html

nginx配置

server {
listen 80;
root /var/www/html;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name mydomain.co.id;
charset utf-8;
location / {
try_files $uri $uri/ /web/index.php$is_args$args;
}

location /api/ {
alias /var/www/html/api/;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}

当我尝试像这样访问模块时: http://mydomain.co.id/api/web/index.php/v1/ref-city/index

始终显示404未找到

我想我错过了Nginx路由设置,因为此代码在apache上运行

1 个答案:

答案 0 :(得分:0)

感谢穆罕默德的回应,我通过编辑nginx配置找到了解决方案

 

    location /api/ {
    if (!-e $request_filename){
    rewrite ^/(.*) /web/index.php?r=$1 last;
    }
    }