Apache2 - Ordner mit Passwort belegen


  • h4Ze
  • 1378 Aufrufe 7 Antworten
  • Apache2 - Ordner mit Passwort belegen

    Hallo Gemeinde! :)

    Ich habe vorhin auf meinem SuSe 9.3 Root einen Apache2 Webserver installiert und stehe nun vor einem kleinem Problemchen. Ich möchte einen Ordner, auf den von aussen frei zugegriffen werden kann, mit einem Passwort belegen. Sprich man soll nach einem Passwort gefragt werden, wenn man die URL des Ordners aufruft. Lässt sich sowas mit Apache realisieren bzw. würde mir da ein anderes Programm helfen?

    Vielen Dank schonmal für eure Tips und Ratschläge.

    MfG h4Ze
  • Tutorials hin oder her, es klappt einfach nicht. :)

    Hab wie beschrieben die .htaccess für den Ordner erstellt und dazu eine .passwd-Datei, in der der User + Passwort festgelegt ist.
    Ich kann aber dennoch die Verzeichnisse aufrufen, ohne ein Passwort eingeben zu müssen, es hat sich einfach nichts geändert.

    Weiss einer Rat? =)

    h4Ze
  • Oje, die Gründe warum das schief gehen kann sind endlos. Deine Fehlerbeschreibung ist ja leider nur ein simples "geht nicht".

    Ich gehe mal davon aus, dass du alle Protokolldateien geprüft hast (Zugriffslog, Fehlerlog), und darin keine Fehlermeldungen aufgetaucht sind.
    Somit ist die Konfiguration syntaktisch korrekt und Fehler beim Anlegen des Users und seines Kennwortes sind auszuschließen.

    Wahrscheinlichster Fehler: die Angabe des Ordners, auf den sich der Schutz bezieht, ist falsch. Dazu wäre es nützlich, den Inhalt der .htaccess-Datei zu sehen und zu wissen, wie der Dateibaum aufbaut ist. Zur Prüfung ist außerdem die URL nötig, über den die Seite aufgerufen wird.

    Zweiter Punkt: in der Hauptkonfigurationsdatei (in der Regel httpd.conf), kann ein Überschreiben von Anweisungen in Ordnerspezifischen .htaccess-Dateien verboten werden. Das geht auf verschiedene Arten (generelles Abschalten von .htaccess oder Verbot einzelner Anweisungen darin). Das solltest du ebenfalls überprüfen.

    Ein beliebter ganz simpler Fehler ist auch ein Schreibfehler im Dateinamen (.htacess statt .htaccess). Sowas übersieht man dann leider schnell.

    Weiter ist das alles leider auch noch davon abhängig, welche Apache-Version du betreibst (inklusive Patchlevel). Ist das die von Suse mitgelieferte Version? Hast du (manuell oder über Yast) Updates eingespielt?

    Um Nebenwirkungen soweit es geht auszuschließen, würde ich eine absolut minimale httpd.conf erstellen und erstmal damit testen. Am besten nur eine Listen-Anweisung und das VirtualHost-Gemüse.

    So, das soll erstmal reichen.

    Grüße
    Michael
  • Danke schonmal für deine Hilfe kelzoo!
    Auf dem RootServer läuft ein Apache 2.0.53 WebServer. Installiert wurde er per YaST und auch per dieses geupdatet.

    Hier mal der Inhalt meiner .htaccess-Datei:

    Quellcode

    1. # .htaccess-Datei für Web-Verzeichnis /lisa
    2. AuthType Basic
    3. AuthName "Passwortgeschützter-Bereich"
    4. AuthUserFile /srv/www/htdocs/lisa/.htpasswd
    5. Require user christopher


    Der DocumentRoot des Apache-Servers lautet: /srv/www/htdocs
    Die Dateien .htaccess und .htpasswd liegen direkt im Ordner /lisa.

    Hier mal der Inhalt meiner httpd.conf:

    Quellcode

    1. #
    2. # /etc/apache2/httpd.conf
    3. #
    4. # This is the main Apache server configuration file. It contains the
    5. # configuration directives that give the server its instructions.
    6. # See <URL:http://httpd.apache.org/docs-2.0/> for detailed information about
    7. # the directives.
    8. # Based upon the default apache configuration file that ships with apache,
    9. # which is based upon the NCSA server configuration files originally by Rob
    10. # McCool. This file was knocked together by Peter Poeml <poeml+apache@suse.de>.
    11. # If possible, avoid changes to this file. It does mainly contain Include
    12. # statements and global settings that can/should be overridden in the
    13. # configuration of your virtual hosts.
    14. # Overview of include files, chronologically:
    15. #
    16. # httpd.conf
    17. # |
    18. # |-- uid.conf . . . . . . . . . . . . . . UserID/GroupID to run under
    19. # |-- server-tuning.conf . . . . . . . . . sizing of the server (how many processes to start, ...)
    20. # |-- sysconfig.d/loadmodule.conf . . . . . [*] load these modules
    21. # |-- listen.conf . . . . . . . . . . . . . IP adresses / ports to listen on
    22. # |-- mod_log_config.conf . . . . . . . . . define logging formats
    23. # |-- sysconfig.d/global.conf . . . . . . . [*] server-wide general settings
    24. # |-- mod_status.conf . . . . . . . . . . . restrict access to mod_status (server monitoring)
    25. # |-- mod_info.conf . . . . . . . . . . . . restrict access to mod_info
    26. # |-- mod_usertrack.conf . . . . . . . . . defaults for cookie-based user tracking
    27. # |-- mod_autoindex-defaults.conf . . . . . defaults for displaying of server-generated directory listings
    28. # |-- mod_mime-defaults.conf . . . . . . . defaults for mod_mime configuration
    29. # |-- errors.conf . . . . . . . . . . . . . customize error responses
    30. # |-- ssl-global.conf . . . . . . . . . . . SSL conf that applies to default server _and all_ virtual hosts
    31. # |
    32. # |-- default-server.conf . . . . . . . . . set up the default server that replies to non-virtual-host requests
    33. # | |--mod_userdir.conf . . . . . . . . enable UserDir (if mod_userdir is loaded)
    34. # | `--conf.d/apache2-manual?conf . . . add the docs ('?' = if installed)
    35. # |
    36. # |-- sysconfig.d/include.conf . . . . . . [*] your include files
    37. # | (for each file to be included here, put its name
    38. # | into APACHE_INCLUDE_* in /etc/sysconfig/apache2)
    39. # |
    40. # `-- vhosts.d/ . . . . . . . . . . . . . . for each virtual host, place one file here
    41. # `-- *.conf . . . . . . . . . . . . . (*.conf is automatically included)
    42. #
    43. #
    44. # Files marked [*] are created from sysconfig upon server restart: instead of
    45. # these files, you edit /etc/sysconfig/apache2
    46. # Filesystem layout:
    47. #
    48. # /etc/apache2/
    49. # |-- conf.d/
    50. # | |-- apache2-manual.conf . . . . . . . conf that comes with apache2-doc
    51. # | |-- mod_php4.conf . . . . . . . . . . (example) conf that comes with apache2-mod_php4
    52. # | `-- ... . . . . . . . . . . . . . . . other configuration added by packages
    53. # |-- default-server.conf
    54. # |-- errors.conf
    55. # |-- httpd.conf . . . . . . . . . . . . . top level configuration file
    56. # |-- listen.conf
    57. # |-- magic
    58. # |-- mime.types -> ../mime.types
    59. # |-- mod_autoindex-defaults.conf
    60. # |-- mod_info.conf
    61. # |-- mod_log_config.conf
    62. # |-- mod_mime-defaults.conf
    63. # |-- mod_perl-startup.pl
    64. # |-- mod_status.conf
    65. # |-- mod_userdir.conf
    66. # |-- mod_usertrack.conf
    67. # |-- server-tuning.conf
    68. # |-- ssl-global.conf
    69. # |-- ssl.crl/ . . . . . . . . . . . . . . PEM-encoded X.509 Certificate Revocation Lists (CRL)
    70. # |-- ssl.crt/ . . . . . . . . . . . . . . PEM-encoded X.509 Certificates
    71. # |-- ssl.csr/ . . . . . . . . . . . . . . PEM-encoded X.509 Certificate Signing Requests
    72. # |-- ssl.key/ . . . . . . . . . . . . . . PEM-encoded RSA Private Keys
    73. # |-- ssl.prm/ . . . . . . . . . . . . . . public DSA Parameter Files
    74. # |-- sysconfig.d/ . . . . . . . . . . . . files that are created from /etc/sysconfig/apache2
    75. # | |-- global.conf
    76. # | |-- include.conf
    77. # | `-- loadmodule.conf
    78. # |-- uid.conf
    79. # `-- vhosts.d/ . . . . . . . . . . . . . . put your virtual host configuration (*.conf) here
    80. # |-- vhost-ssl.template
    81. # `-- vhost.template
    82. ### Global Environment ######################################################
    83. #
    84. # The directives in this section affect the overall operation of Apache,
    85. # such as the number of concurrent requests.
    86. # run under this user/group id
    87. Include /etc/apache2/uid.conf
    88. # - how many server processes to start (server pool regulation)
    89. # - usage of KeepAlive
    90. Include /etc/apache2/server-tuning.conf
    91. # ErrorLog: The location of the error log file.
    92. # If you do not specify an ErrorLog directive within a <VirtualHost>
    93. # container, error messages relating to that virtual host will be
    94. # logged here. If you *do* define an error logfile for a <VirtualHost>
    95. # container, that host's errors will be logged there and not here.
    96. ErrorLog /var/log/apache2/error_log
    97. # generated from APACHE_MODULES in /etc/sysconfig/apache2
    98. Include /etc/apache2/sysconfig.d/loadmodule.conf
    99. # IP addresses / ports to listen on
    100. Include /etc/apache2/listen.conf
    101. # predefined logging formats
    102. Include /etc/apache2/mod_log_config.conf
    103. # generated from global settings in /etc/sysconfig/apache2
    104. Include /etc/apache2/sysconfig.d/global.conf
    105. # optional mod_status, mod_info
    106. Include /etc/apache2/mod_status.conf
    107. Include /etc/apache2/mod_info.conf
    108. # optional cookie-based user tracking
    109. # read the documentation before using it!!
    110. Include /etc/apache2/mod_usertrack.conf
    111. # configuration of server-generated directory listings
    112. Include /etc/apache2/mod_autoindex-defaults.conf
    113. # associate MIME types with filename extensions
    114. TypesConfig /etc/apache2/mime.types
    115. DefaultType text/plain
    116. Include /etc/apache2/mod_mime-defaults.conf
    117. # set up (customizable) error responses
    118. Include /etc/apache2/errors.conf
    119. # global (server-wide) SSL configuration, that is not specific to
    120. # any virtual host
    121. Include /etc/apache2/ssl-global.conf
    122. # forbid access to the entire filesystem by default
    123. <Directory />
    124. Options None
    125. AllowOverride None
    126. Order deny,allow
    127. Deny from all
    128. </Directory>
    129. # use .htaccess files for overriding,
    130. AccessFileName .htaccess
    131. # and never show them
    132. <Files ~ "^\.ht">
    133. Order allow,deny
    134. Deny from all
    135. </Files>
    136. # List of resources to look for when the client requests a directory
    137. DirectoryIndex index.html index.html.var
    138. ### 'Main' server configuration #############################################
    139. #
    140. # The directives in this section set up the values used by the 'main'
    141. # server, which responds to any requests that aren't handled by a
    142. # <VirtualHost> definition. These values also provide defaults for
    143. # any <VirtualHost> containers you may define later in the file.
    144. #
    145. # All of these directives may appear inside <VirtualHost> containers,
    146. # in which case these default settings will be overridden for the
    147. # virtual host being defined.
    148. #
    149. Include /etc/apache2/default-server.conf
    150. # Another way to include your own files
    151. #
    152. # The file below is generated from /etc/sysconfig/apache2,
    153. # include arbitrary files as named in APACHE_CONF_INCLUDE_FILES and
    154. # APACHE_CONF_INCLUDE_DIRS
    155. Include /etc/apache2/sysconfig.d/include.conf
    156. ### Virtual server configuration ############################################
    157. #
    158. # VirtualHost: If you want to maintain multiple domains/hostnames on your
    159. # machine you can setup VirtualHost containers for them. Most configurations
    160. # use only name-based virtual hosts so the server doesn't need to worry about
    161. # IP addresses. This is indicated by the asterisks in the directives below.
    162. #
    163. # Please see the documentation at
    164. # <URL:http://httpd.apache.org/docs-2.0/vhosts/>
    165. # for further details before you try to setup virtual hosts.
    166. #
    167. # You may use the command line option '-S' to verify your virtual host
    168. # configuration.
    169. #
    170. Include /etc/apache2/vhosts.d/*.conf
    171. # Note: instead of adding your own configuration here, consider
    172. # adding it in your own file (/etc/apache2/httpd.conf.local)
    173. # putting its name into APACHE_CONF_INCLUDE_FILES in
    174. # /etc/sysconfig/apache2 -- this will make system updates
    175. # easier :)
    Alles anzeigen


    Die httpd.conf ist quasi noch Standard von der Installation. Ich habe da auch einen Abschnitt gefunden, wo auf die .htaccess-Dateien näher eingegangen wird ... Weiss aber nicht genau wie ich diesen Abschnitt editieren soll :rolleyes:

    EDIT: Hier noch der Link zum Server: h**p://85.214.25.64/
  • hai,

    hatte das gleiche Prob. unter Debian, gut ist zwar auch Linux aber die Apache2 verzeichnis Struktur ist etwas anders, soll jetzt aber nicht das problem sein.

    Bei mir war es so das ich unter /sites-available/default bei diesem abschnitt

    Quellcode

    1. # forbid access to the entire filesystem by default
    2. <Directory />
    3. Options None
    4. AllowOverride None
    5. Order deny,allow
    6. Deny from all
    7. </Directory>


    das AllowOverride hab auskommentieren muessen. Das bedeutet das, dass auslesen DEINER .htaccess datei erlaubt wird.
    Bei dir steht jetzt das ganze in der httpd.conf und ist nicht auskommentiert:confused:

    Andere Frage, wie hast du die .htpasswd angelgt :confused:
  • Hallo uwe!

    Danke schonmal für deine Hilfe! Leider half das auskommentieren garnichts. Weiß sonst noch jemand Rat?

    Zu deiner Frage:
    Du kannst mittels WinSCP in jedem Ordner eine neue Datei anlegen, die du dann auch benennen kannst. Nach dem Anlegen öffnet sich die Datei autom. und du kannst sie mit Inhalt füllen ;)

    MfG

  • # forbid access to the entire filesystem by default
    <Directory />
    Options None
    AllowOverride all
    Order deny,allow
    Deny from all
    </Directory>

    # use .htaccess files for overriding,
    AccessFileName .htaccess
    # and never show them
    <Files ~ "^\.ht">
    Order allow,deny
    Deny from all
    </Files>


    Wenn diese Anweisung auf None gesetzt wird, dann werden .htaccess-Dateien komplett ignoriert. In diesem Fall wird der Server nicht einmal versuchen, die .htaccess-Dateien im Dateisystem zu lesen.

    Wenn diese Anweisung auf All gesetzt wird, dann ist jede Direktive in den .htaccess-Dateien erlaubt, die den Kontext .htaccess besitzt.

    Dann sollte es gehen mit all.

    Mfg kc
    [size=1]It's not a bug, it's a feature.[/size]
    [size=3]Bin vom 05.06.2006 - 10.06.2006 im Urlaub[/Size]