【发布时间】:2014-11-10 00:49:04
【问题描述】:
我在配置将从主域的 /api/ 段运行的 laravel 配置时遇到问题。 想法是在 subdomain.domain.com 主要 Angular 应用程序和 subdomain.domain.com/api/ laravel php 服务器配置中提供服务。
更新 #1
我已经设法使用这个配置从 /api/ 段运行 laravel
server {
listen 80;
server_name subdomain.domain.com;
root /var/www/subdomain.domain.com/client/monkey/dist;
access_log /var/www/subdomain.domain.com.access.log;
error_log /var/www/subdomain.domain.com.error.log;
rewrite_log on;
index index.php index.html;
location / {
root /var/www/subdomain.domain.com/client/monkey/dist;
index index.html;
if (!-e $request_filename){ # handles page reload
rewrite ^(.*)$ /index.html break;
}
}
location /api/ {
root /var/www/subdomain.domain.com/server/;
try_files $uri $uri/ /api/index.php$is_args$args;
}
location ~ /api/.+\.php$ {
root /var/www/subdomain.domain.com/server/;
rewrite ^/api/(.*)$ /$1 break;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
fastcgi_param MONKEY_ENV production;
fastcgi_split_path_info ^(.+?\.php)(/.*)?$;
# fastcgi_split_path_info ^(.+\.php)(.*)$;
}
}
唯一剩下的问题是,当我使用 subdomain.domain.com/api/segment1/segment... 时,我需要添加 routes.php
Route::group(['prefix' => 'api'], function () {
// my routes settings
});
因为 laravel 从 suddomain.domain.com/ 作为根路径开始。如何重写 /api/ 以便 laravel 以 /api/ 作为路由起点?
【问题讨论】:
-
你在用 Laravel 做任何事情外部
/api?如果没有,那你为什么不把/api设为 Laravel 的公用文件夹? -
/api 路径仅适用于 laravel,因为这是我的 laravel 处理的后端。因此,如果我将 /server 重命名为 /api 它应该可以工作吗?我是否需要删除配置中的任何规则或添加额外的规则?
标签: php angularjs laravel nginx