기본 인증으로 Nginx에서 Piwik을 보호하지만 piwik.js 액세스를 허용합니다.

기본 인증으로 Nginx에서 Piwik을 보호하지만 piwik.js 액세스를 허용합니다.

내 서버에서 nginx를 실행 중이고 최근에 다음 구성으로 Piwik을 설치했습니다.

server {
  listen 443 ssl spdy;
  server_name analytics.example.org;
  root /srv/www/analytics.example.org;
  index index.php;

  ssl_certificate ssl-certificates/wildcard.example.org.crt;
  ssl_certificate_key ssl-certificates/wildcard.example.org.key;

  access_log           /var/log/nginx/analytics.example.org_access.log;
  error_log            /var/log/nginx/analytics.example.org_error.log;

  auth_basic           "HTTP Basic Authentication";
  auth_basic_user_file htpasswd/example;

  satisfy              any;
  include              example_ip;
  deny                 all;

  location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
    expires max;
  }

  location = /robots.txt {
    return 200 "User-agent: *\nDisallow: /\n";
  }

  location / {
    try_files $uri $uri/ /index.php?$args;
  }

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

  location = /piwik.js {
    satisfy any;
    allow all;
    auth_basic off;
    try_files $uri =404;
  }
}

앱 자체에서 요청하고 항상 사용자 이름과 비밀번호를 요구하기 때문에 /piwik.js에 대한 기본 인증을 끄려고 합니다.

내가 여기서 뭘 잘못하고 있는 걸까?

--- 업데이트 1 ---

업데이트된 구성:

...
location = /piwik.js {
  satisfy any;
  allow all;
  auth_basic off;
  try_files $uri =404;
}

location / {
  auth_basic           "Bitte authentifiziere dich.";
  auth_basic_user_file htpasswd/pass;

  satisfy              any;
  include              pass_ip;
  deny                 all;

  try_files $uri $uri/ /index.php?$args;
}
...

이제 앱에서 piwik.js에 액세스하고 Analytics.example.org에 대한 기본 인증도 요청하겠습니다. 그런데 취소를 클릭하면 웹사이트의 일부가 로드되고 다음 기본 인증, 취소, 로드 등이 발생합니다.

--- 업데이트 2 ---

또한 지시문에 기본 인증 항목을 추가했는데 location ~ .php$지금은 작동하고 있지만 두 위치에 두는 것은 옳지 않은 것 같습니다. 어쨌든 좀 더 멋지게 만들 수 있을까요?

답변1

최근에 비슷한 문제가 발생했으며 이제 위치 블록이 올바른 것 같습니다.

Nginx: 영역 기반 인증 기본의 선택적 켜기/끄기

지속적인 흐름은 아마도 브라우저 캐싱으로 인한 것일 수 있으며 이로 인해 이 주제에 대해서도 몇 시간의 시간 낭비가 발생했습니다. http 인증 설정을 변경할 때마다 브라우저를 완전히 닫고 이상적으로는 재설정한 다음 페이지를 다시 열고 새 설정이 예상대로 작동하는지 확인하세요. 그것은 나를 위해 트릭을 만들었습니다.

위의 답변에 주석으로 추가했지만 아직 담당자 포인트가 충분하지 않습니다.

관련 정보