htaccess will nicht

f0x

Punk
Hallo,
ich verzweifel gerade an der Aktivierung einer Zugangskontrolle für einen Unterordner in meiner Website.

Ich habe eine .htaccess Datei mit den Credentials von htpasswd erstellt und sie www:daemon übergeben. Den Ordner in dem sie liegt ebenfalls.
Ich hab nach den Änderungen natürlich den Daemon einmal neu gestartet...
Meine httpd.conf sieht jetzt so aus:

Code:
server $domain {
  listen on $ext_if tls port 443
  directory {index "index.html" }
  location "/*.php*" {
  root { "/htdocs" }
  fastcgi socket "/run/php-fpm.sock"
  }
  location "/*" {
  root { "/htdocs" }
  }
  tls {
  certificate "/etc/ssl/letsencrypt/fullchain.pem"
  key "/etc/ssl/private/httpd.key"
  }
  location "/n/*" {
  directory auto index
  authenticate with "/htdocs/n/backend/.htaccess"
  }
}
Wenn ich nun in den Ordner gehe werde ich weder nach Credentials gefragt, noch macht der Server automatisches Directory-Listing.

Kann mir jemand sagen, warum der Daemon das nicht tun mag? :confused:

Danke im Voraus,
f0x
 
Wäre vermutlich auch hilfreich zu wissen welche Webserver Software da läuft. Apache ist es nach der Syntax ja wohl nicht.
 
Hallo,

Ich kenne httpd von OpenBSD nicht wirklich aber beim Apache sollte das htpasswd File nicht im zu schützenden Verzeichnis liegen. Daher würde ich dieses man nach /etc/ verschieben und es in htpasswd umbenennen. Was sagt das Logfile dazu?

Gruss
 
Code:
[...]
  location "/n/*" {
  directory auto index
  authenticate with "/htdocs/n/backend/.htaccess"
  }
}
[...]

Nimm mal bitte das authenticate with "/htdocs/n/backend/.htaccess" aus deiner config raus, restarte den httpd und schaue, ob das directory listing dann funktioniert.

Ich vermute, mit .htaccess und credentials wirst Du bei httpd kein Glück haben, da dies meines Wissens nach nicht unterstützt wird. Versuchs mal mit

authenticate with "/htpasswd"


Code:
$ doas htpasswd /var/www/htpasswd example
Password:
Retype Password:
$ doas chown www:daemon /var/www/htpasswd


Um den Zugriff auf gewisse directories und files zu sperren, kasst Du auch sowas hier nutzen:

Code:
location "/n/*" { block }
 
Schau mal, ob du wirklich eine htpasswd Datei angelegt hast. Es gibt auch noch htdigest, das ein bisschen anders ist. Ich kenne den OpenBSD httpd nicht, möglicherweise unterstützt er nur eines von beiden formaten.
 
@foxit Danke für den Tipp. Ich hatte das zum testen erstmal stumpf in die Directory gemacht...

@midnight Auch wenn ich die authenticate Geschichte weglasse, gibt es kein Listing. Auch { block } hat keinerlei Effekt. Ich kann immer noch auf die Files zugreifen :confused: Aber in der httpd(5) steht doch:
Code:
[no] authenticate [realm] with htpasswd
Authenticate a remote user for realm by checking the credentials against the user authentication file htpasswd. The file name is relative to the chroot and must be readable by the www user. Use the no authenticate directive to disable authentication in a location.
Dann muss das doch irgendwie gehen? Wäre echt blöd wenn nicht :(

Ich brauch einfach nur eine User-Auth ohne fucking PHP. Gibt es da sonst eine Möglichkeit?

@derOliver Also die File ist ganz einfach username:$hash...
 
Die Logs zeigen keinerlei Fehler oder ähnliches an. Wenn ich in die Directory gehe, sagt der Server einfach "/n/index.html (403 Forbidden)". Wenn ich auf eine Datei gehe, zB. file.html, wird normal die File ausgeliefert.

Nun hab ich folgendes gemacht, ich hab einfach mal zum testen die httpd.conf wie folgt geändert:
Code:
server $domain {
  listen on $ext_if tls port 443
  directory {index "index.html" }

  authenticate with "/.htpasswd"

  location "/*.php*" {
  root { "/htdocs" }
  fastcgi socket "/run/php-fpm.sock"
  }
  location "/*" {
  root { "/htdocs" }
  }
  tls {
  certificate "/etc/ssl/letsencrypt/fullchain.pem"
  key "/etc/ssl/private/httpd.key"
  }
  location "/n/*" {
  directory auto index
  }
}
Habe natürlich vorher die .htpasswd in /var/www gepackt... Und siehe da, es klappt.
Es scheint also ein Problem damit zu geben, wie ich die location setze. Irgendwie zeigt die scheinbar nicht auf den Unterordner "n". Hab es mit "/htdocs/n/*", mit einfach nur "/n" und mit nem zusätzlichem root { "/htdocs" } innerhalb von location probiert, tut sich aber nix.
Kann es sein, dass die falsch gesetzt ist? Der Ordner ist in /var/www/htdocs/n. Da ja auch { block } keinen Einfluss hatte, erscheint mir das die logischste Erklärung!

LG
 
AAAAaaaaahhh, ich habs :)
Der Teufel steckt wie immer im Detail!
httpd(5) sagt:
Code:
location path {...}
Specify server configuration rules for a specific location. The path argument will be matched against the request path with shell globbing rules. In case of multiple location statements in the same context, the first matching location statement will be put into effect, while all later ones will be ignored. Therefore it is advisable to match for more specific paths first and for generic ones later on. A location section may include most of the server configuration rules except alias, connection, hsts, listen on, location, tcp and tls.
Specific first, generic later.
Hab das location in seiner Ursprungsform nach oben gesetzt. Alles geht. Directory listing als auch Authentication.

Danke für die anregungen und Hilfe ;)

LG, f0x
 
Zurück
Oben