PHP API-Nginx给了我无效的数据类型头



我对Apache有一些经验,但现在我转到Nginx学习一些新东西。最后使用了基本的PHP,让我们在我的域上加密。(是的,我很乐意尝试新事物(

我想要一些由Nginx提供React的静态文件(我听说这是Nginx擅长的(,以及在/API/{RESOURCE}/{ACTION|ID}URI下使用PHP的REST API。

现在,我有了目录/API/,并配置(使用了一些谷歌搜索(将域.tld/(API|nenenebb API(/下的所有内容传递到/API/index.php(我使用Nette FW(。index.php与php-FPM一起正常工作并显示,但当使用RESOURCE的端点时,它会给我一些标题为Content-Type: application/octet-stream的哈希字符串(或随机字符串(,即使我从php发送contentType这是我的2个域";虚拟主机";config(HTTPS重定向除外,效果良好(;

server {
listen 443 ssl;
listen [::]:443 ssl;
server_name domain.tld *.domain.tld username.tld *.username.cz;
# redirect other domains to main
if ($host != 'domain.tld') {
return 301 https://domain.tld$request_uri;
}

root /home/username/www/domain.tld/www;
index index.php index.html index.htm;

location / {
try_files $uri $uri/ /index.php =404;
}
location /API {
try_files $uri $uri/ /index.php =404;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
}

ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem; # managed by Certbot
}

有什么想法吗?感谢

感谢Ivan Shatsky的评论,发现了真正的问题——它重定向到404而不是index.php

所以现在在中尝试_files

location /API {
try_files $uri $uri/ /index.php =404;
}

成为try_files $uri $uri/ /API/index.php;

(是的,我想它需要整个路径(

非常感谢。我的学校项目现在可以工作了:(

最新更新