【发布时间】:2021-12-19 00:29:20
【问题描述】:
我有一些使用 Apache 的经验,但现在我切换到 Nginx 来学习一些新东西。最后让它使用基本的 PHP,让我们在我的域上加密。 (是的,我很乐意尝试新事物)
我想要一些由 Nginx 提供的带有 React 的静态文件(我听说这是 Nginx 擅长的东西),以及在/API/{RESOURCE}/{ACTION|ID} URI 下使用 PHP 的 REST API。
现在,我有目录 /API/ 并配置(使用一些谷歌搜索)将 domain.tld/(api|API)/ 下的所有内容传递给 /API/index.php(我使用的是 Nette FW)。
index.php 在 PHP-FPM 和显示中按预期工作,但是当使用带有 RESOURCE 的端点时,即使我从 PHP 发送 contentType,它也会给我一些带有标题 Content-Type: application/octet-stream 的哈希字符串(或随机字符串)
这是我的 2 个域“虚拟主机”配置(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
}
任何想法有什么问题吗?谢谢
【问题讨论】:
-
如果您将
try_files $uri $uri/ /index.php =404;更改为try_files $uri $uri/ /index.php;会发生什么?
标签: php rest nginx configuration fpm