【发布时间】:2014-09-06 10:25:39
【问题描述】:
我为后端运行 Laravel,为前端运行 AngularJS。我的应用程序层次结构是
/application
/app
/bootstrap
/vendor
/public
/api
index.php <-- This is the Laravel "public" index
index.html
bootstrap.js
所以基本上,默认的 public 文件夹用于 AngularJS 前端,/public/api 用于 Laravel。
我不知道如何编写 NGINX 配置!这就是我目前所拥有的
server {
listen 80;
root PATH_TO_PUBLIC;
index index.php index.html index.htm;
server_name mysite.com;
# AnuglarJS UI Front /index.html
location / {
try_files $uri $uri/
}
# Laravel Back-end /api/index.php
location /api/ {
try_files $uri $uri/ /index.php$is_args$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on the php-fpm socket
location ~ \.php$ {
try_files $uri / =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Laravel 中唯一有效的页面是 /api/index.php。即使像/api/index.php/my-resource 这样的东西也不起作用。
编辑
当我访问/api/index.php 时,Laravel 开始工作并开始工作。当我访问任何其他页面时(例如/api/sessions 或/api/index.php/sessions,它会加载主页/index.html。
【问题讨论】:
-
当你说不起作用时,你是什么意思? nginx 是否抛出 404 或其他错误,或者您是否收到 NotFoundHttpExceptions(来自 laravel)?还是别的什么?
-
不,它会加载主页
/index.html。我会更详细地更新问题 -
你为什么要改变 Laravel 的结构?我不明白。
标签: angularjs laravel nginx laravel-4