【发布时间】:2016-12-29 06:28:35
【问题描述】:
我正在尝试创建一个在后端使用 codeigniter 并在前端使用 angularjs 的网站。 对于后端,我使用 nginx 作为服务器。 目前我在正确配置 nginx 时遇到问题。我想要实现的是将 codeigniter 和 angularjs 应用程序放在单独的文件夹中。我想要的是访问如下
- 来自 my_website.com/api 的 codeigniter
- 来自 my_website.com 的角度
就文件夹而言,我想将它们保留在:
- codeigniter:/var/www/html/api
- 角度:/var/www/html/angular
到目前为止,我已经设法让它在同一个文件夹中工作。所以现在我在 /var/www/html 中有 codeigniter 并且 angular 文件夹在同一个目录中。这样我就可以从 my_website.com/ 访问 codeigniter 并从 my_website.com/app 访问 angular,这不是我想要的。
我为 nginx /etc/nginx/sites-available/default 文件尝试了多种不同的设置,但每次都有一些问题。我所拥有的最远的是将它们放在单独的文件夹中,但 codeigniter 仅适用于 default_controller,我无法访问任何其他文件。 这是当前的工作配置。
server {
listen 80;
listen [::]:80 default_server ipv6only=on;
root /var/www/html;
server_name localhost;
index index.php index.htm index.html;
location /app/ {
root /var/www/html/angular;
try_files $uri/ $uri index.html =404;
}
location / {
try_files $uri $uri/ /index.php;
#index index.html;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
include fastcgi_params;
}
}
这是一个简单的配置,我只是尝试从演示子文件夹运行 codeigniter,
server {
listen 80;
server_name localhost;
root /var/www/html;
autoindex on;
index index.php;
location / {
#try_files $uri $uri/ /index.php;
try_files $uri $uri/ /index.php$request_uri;
location = /demo/index.php {
try_files $uri $uri/ /index.php$request_uri;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME /var/www/html/demo$fastcgi_script_name;
include fastcgi_params;
}
}
location ~ \.php$ {
return 444;
}
}
这里 my_website.com/demo/index.php 工作正常,但 my_website.com/demo/index.php/welcome 显示 500 Internal Server Error
我希望我说清楚。 我尝试了很多在网上找到的不同配置,但我总是遇到一些麻烦。你们中的任何人都可以为这个问题提出一些简单的解决方案吗?
谢谢, 马特乌斯
【问题讨论】:
标签: php codeigniter nginx url-rewriting vagrant