hekwan
hekwan

Reputation: 71

Nginx 404 Not Found when access module on yii2

I have project API with yii2 and nginx, my folder structure:

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

setting on web.php

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

on nginx I put my folder API app with structure /var/www/html/api

my root folder /var/www/html

nginx configuration

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;
}
}

when I tried to access my module like : http://mydomain.co.id/api/web/index.php/v1/ref-city/index

always show 404 Not found

I think I've missed with nginx route setting because this code running on apache

Upvotes: 1

Views: 1435

Answers (1)

hekwan
hekwan

Reputation: 71

Thanks Muhammad for your respon, i found solution by edit nginx configuration like this

 

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

Upvotes: 0

Related Questions