我在关闭GraphQL api的验证方面遇到了困难。它一直让构建失败。这是我现在的情况,我认为是正确的。
location / {
try_files $uri $uri/ @rewrites;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
}
location ^~ /api/ {
auth_basic off;
fastcgi_read_timeout 1200;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
# below for some setups on php 7.4
#include snippets/fastcgi-php.conf;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location @rewrites {
rewrite ^(.*) /index.php?p=$1 last;
}
解决方案 & 更新
location ^~ /api {
auth_basic off;
try_files $uri $uri/ /index.php?$args;
}
参考。
https:/stackoverflow.coma6218083212257950
在Gatsby网站上关闭GraphQL api的nginx认证。
我已经尝试在我的终端复制这个问题,但工作正常。
我使用OpenResty,并添加了一个标题 X-reached
与 more_set_headers
(你可以用 add_header
在 /api/
的位置块。
这是我的Nginx配置
location / {
try_files $uri $uri/ @rewrites;
auth_basic "restricted";
auth_basic_user_file /usr/local/openresty/nginx/conf/conf.d/.htpasswd;
}
location ^~ /api/ {
auth_basic off;
try_files $uri $uri/ /index.php?$args;
more_set_headers 'X-reached true';
}
location @rewrites {
rewrite ^(.*) /index.php?p=$1 last;
}
你可以用下面的命令检查响应中的头。
curl -XGET -IL https://site-name.tld/api/path
或者你可以使用浏览器中的网络选项卡检查。
2.检查是否有一些重定向发生。
感谢Devarshi,这才是有效的方法。
location ^~ /api {
auth_basic off;
try_files $uri $uri/ /index.php?$args;
}