Отключение аутентификации пользователя в nginx для GraphQL api для сайта Gatsby - PullRequest
0 голосов
/ 30 мая 2020

Я пытаюсь настроить аутентификацию пользователя на своем сайте Gatsby, но разрешаю GraphQL api.

Вот что у меня сейчас: ниже

Я пытался добавить то, что находится в location ~ .php $, а также то, что находится в перезаписи, но получил ту же ошибку.

location / {
    try_files $uri $uri/ @rewrites;

    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;

    location ^~ /api/ {
        rewrite ^(.*) /index.php?p=$1 last;
        auth_basic off;
    }
}

location @rewrites {
    rewrite ^(.*) /index.php?p=$1 last;
}

# PHP
location ~ \.php$ {
     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;
}

1 Ответ

0 голосов
/ 30 мая 2020

Одна ошибка - цитирование off.

Просто удалите кавычки: замените "off" на off. Тогда это будет фактическая конфигурация off, а не строка в кавычках.

Другое - это местоположение без регулярного выражения (^~) для /api/. location ^~ лучше всего объяснять как префиксное местоположение с наивысшим приоритетом. Это не тип расположения регулярного выражения.

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;
}

# PHP
location ~ \.php$ {
     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;
} 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...