好吧,好几天以来,我一直在挠头,尝试各种组合以使该死的东西起作用。
我正在使用javascript前端,我想使用Laravel作为后端API,并从/ api /目录中加载它。我正在使用Nginx作为Web服务器,但是我不知道为什么我的Nginx配置不能很好地工作。
我的配置如下;
server {
listen 80;
server_name .reactproject.com;
root "/home/reactproject/code";
index index.html index.htm index.php;
charset utf-8;
location ^~ /api {
alias "/home/reactproject/api/public";
try_files $uri $uri/ @api;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
location @api {
rewrite ^/api/(.*)$ /index.php/$1 last;
}
location / {
}
access_log off;
error_log /var/log/nginx/reactproject.com-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ /\.ht {
deny all;
}
}
前端完美加载,没有问题,但是当我加载reactproject.com/api/时,出现以下错误;
No input file specified.
如果我检查日志,则看到此错误;
FastCGI sent in stderr: "Unable to open primary script: /home/reactproject/api/public/api/index.php (No such file or directory)" while reading response header from upstream, client: 192.168.10.1, server: reactproject.com, request: "GET /api/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "reactproject.com"
无论我做什么,它始终将/ api /附加到api的位置别名的结尾。
我要做的就是通过reactproject.com的/ api /目录加载我的laravel API路由
任何帮助将不胜感激。