[英]Codeigniter 4 in subfolder with Nginx
我正在玩 CodeIgniter 4.0.0-rc3。 我希望将我的 Codeigniter 应用程序放在名为 rest 的子文件夹中。 所以我当前的文件夹结构如下所示:
-Myproject
-- dev
-- VuejS app
-- rest (my codeigniter app)
--- app
--- public
--- system
--- etc...
我当前的 Nginx 配置如下
server {
# Port that the web server will listen on.
listen 80;
listen [::]:80;
# Host that will serve this project.
server_name my-app.test www.my-app.test;
# The location of our project directory.
root /home/vagrant/Myproject;
# Point index to the VUEJs.
index index.html index.htm;
# Point to initial home page
location / {
try_files $uri /index.html;
}
# Point to REST API
location /rest {
index /rest/public/index.php;
try_files $uri $uri/ /rest/public/index.php;
}
# PHP FPM configuration.
location ~* \.php$ {
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
在 codeigniter 应用程序中我已配置(App.php)
public $baseURL = 'http://my-app.test/rest';
public $indexPage = '';
我的问题:当我访问 url http://my-app.test/rest上的页面时,出现以下错误
Controller or its method is not found: App\Controllers\Rest::index
如何正确配置我的应用程序,以便我能够从子文件夹中调用我的 rest api(codeigniter 应用程序)?
如果您需要任何其他信息,请告诉我,我会提供。 谢谢!
更新
我发现当我添加路线时,我需要在每条路线之前指定 /rest/ 。 所以我当前的 $routes->get 看起来像这样。
$routes->get('/rest/', 'Home::index');
有没有办法指定所有路由都有/rest/
值,而不是为所有 $routes 写这个?
试试这个也许对你有帮助我认为你应该改变
server {
# Port that the web server will listen on.
listen 80;
listen [::]:80;
# Host that will serve this project.
server_name my-app.test www.my-app.test;
# The location of our project directory.
root /home/vagrant/Myproject;
# Point index to the VUEJs.
index index.html index.htm;
# Point to initial home page
location / {
try_files $uri /index.html;
}
# Point to REST API
location / {
index /rest/public/index.php;
try_files $uri $uri/ /rest/public/index.php;
}
# PHP FPM configuration.
location ~* \.php$ {
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.