Unable to access private directory with user based security on Apache Centos 7

General support questions
Post Reply
qwerty1111
Posts: 25
Joined: 2016/11/23 13:22:32

Unable to access private directory with user based security on Apache Centos 7

Post by qwerty1111 » 2018/12/06 10:57:50

I'm trying, for test purposes, to set up a User based security access on a virtual host with Apache.

I can access to the virtual host paris.dublin.local through Firefox but as soon as I set up a private directory called "secret" limited to only one user with ht access, I keep getting the following error message:

404 Not found The requested URL/secret was not found on this server.

There is my configuration:

Code: Select all

[root@paris ~]# cd /var/www/html/
[root@paris html]# ll
total 0
drwxr-xr-x. 2 root root 23 Dec  5 10:29 car
drwxr-xr-x. 2 root root  6 Dec  5 09:57 secret
[root@paris html]



[root@paris ~]# cd /etc/httpd/conf.d/
[root@paris conf.d]# ll
total 40
-rw-r--r--. 1 root root 2893 Jun 17  2014 autoindex.conf
-rw-r--r--. 1 root root  293 Dec  5 10:32 car.conf
-rw-r--r--. 1 root root  401 Jun 10  2014 fcgid.conf
-rw-r--r--. 1 root root  295 Jun 17  2014 manual.conf
-rw-r--r--. 1 root root  366 Jun 17  2014 README
-rw-r--r--. 1 root root 9426 Jun 17  2014 ssl.conf
-rw-r--r--. 1 root root 1252 Jun 17  2014 userdir.conf
Content of car.conf :

Code: Select all

<VirtualHost *:80>
    ServerAdmin webmaster@paris.dublin.local
    DocumentRoot "/var/www/html/car"
    ServerName paris.dublin.local
    #ErrorLog "/var/log/httpd/dummy-host2.example.com-error_log"
    #CustomLog "/var/log/httpd/dummy-host2.example.com-access_log" common
</VirtualHost>
Part of the etc/http/conf/httpd.conf with the lines I added to this file:

Code: Select all

130 <Directory "/var/www/html/car">
131 AllowOverride none
132 Require all granted
133 </Directory>
134
135 <Directory "/var/www/html/secret">
136 AuthType Basic
137 AuthName "My secret file"
138 AuthUserFile /etc/httpd/htpasswd
139 Require user robert
140 </Directory>
Full content of /etc/httpd/conf/httpd.conf

Code: Select all

1 #
  2 # This is the main Apache HTTP server configuration file.  It contains the
  3 # configuration directives that give the server its instructions.
  4 # See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.
  5 # In particular, see
  6 # <URL:http://httpd.apache.org/docs/2.4/mod/directives.html>
  7 # for a discussion of each configuration directive.
  8 #
  9 # Do NOT simply read the instructions in here without understanding
 10 # what they do.  They're here only as hints or reminders.  If you are unsure
 11 # consult the online docs. You have been warned.
 12 #
 13 # Configuration and logfile names: If the filenames you specify for many
 14 # of the server's control files begin with "/" (or "drive:/" for Win32), the
 15 # server will use that explicit path.  If the filenames do *not* begin
 16 # with "/", the value of ServerRoot is prepended -- so 'log/access_log'
 17 # with ServerRoot set to '/www' will be interpreted by the
 18 # server as '/www/log/access_log', where as '/log/access_log' will be
 19 # interpreted as '/log/access_log'.
 20
 21 #
 22 # ServerRoot: The top of the directory tree under which the server's
 23 # configuration, error, and log files are kept.
 24 #
 25 # Do not add a slash at the end of the directory path.  If you point
 26 # ServerRoot at a non-local disk, be sure to specify a local disk on the
 27 # Mutex directive, if file-based mutexes are used.  If you wish to share the
 28 # same ServerRoot for multiple httpd daemons, you will need to change at
 29 # least PidFile.
 30 #
 31 ServerRoot "/etc/httpd"
 32
 33 #
 34 # Listen: Allows you to bind Apache to specific IP addresses and/or
 35 # ports, instead of the default. See also the <VirtualHost>
 36 # directive.
 37 #
 38 # Change this to Listen on specific IP addresses as shown below to
 39 # prevent Apache from glomming onto all bound IP addresses.
 40 #
 41 #Listen 12.34.56.78:80
 42 Listen 80
 43
 44 #
 45 # Dynamic Shared Object (DSO) Support
 46 #
 47 # To be able to use the functionality of a module which was built as a DSO you
 48 # have to place corresponding `LoadModule' lines at this location so the
 49 # directives contained in it are actually available _before_ they are used.
 50 # Statically compiled modules (those listed by `httpd -l') do not need
 51 # to be loaded here.
 52 #
 53 # Example:
 54 # LoadModule foo_module modules/mod_foo.so
 55 #
 56 Include conf.modules.d/*.conf
 57
 58 #
 59 # If you wish httpd to run as a different user or group, you must run
 60 # httpd as root initially and it will switch.
 61 #
 62 # User/Group: The name (or #number) of the user/group to run httpd as.
 63 # It is usually good practice to create a dedicated user and group for
 64 # running httpd, as with most system services.
 65 #
 66 User apache
 67 Group apache
 68
 69 # 'Main' server configuration
 70 #
 71 # The directives in this section set up the values used by the 'main'
 72 # server, which responds to any requests that aren't handled by a
 73 # <VirtualHost> definition.  These values also provide defaults for
 74 # any <VirtualHost> containers you may define later in the file.
 75 #
 76 # All of these directives may appear inside <VirtualHost> containers,
 77 # in which case these default settings will be overridden for the
 78 # virtual host being defined.
 79 #
 80
 81 #
 82 # ServerAdmin: Your address, where problems with the server should be
 83 # e-mailed.  This address appears on some server-generated pages, such
 84 # as error documents.  e.g. admin@your-domain.com
 85 #
 86 ServerAdmin root@localhost
 87
 88 #
 89 # ServerName gives the name and port that the server uses to identify itself.
 90 # This can often be determined automatically, but we recommend you specify
 91 # it explicitly to prevent problems during startup.
 92 #
 93 # If your host doesn't have a registered DNS name, enter its IP address here.
 94 #
 95 #ServerName www.example.com:80
 96
 97 #
 98 # Deny access to the entirety of your server's filesystem. You must
 99 # explicitly permit access to web content directories in other
100 # <Directory> blocks below.
101 #
102 <Directory />
103     AllowOverride none
104     Require all denied
105 </Directory>
106
107 #
108 # Note that from this point forward you must specifically allow
109 # particular features to be enabled - so if something's not working as
110 # you might expect, make sure that you have specifically enabled it
111 # below.
112 #
113
114 #
115 # DocumentRoot: The directory out of which you will serve your
116 # documents. By default, all requests are taken from this directory, but
117 # symbolic links and aliases may be used to point to other locations.
118 #
119 DocumentRoot "/var/www/html"
120
121 #
122 # Relax access to content within /var/www.
123 #
124 <Directory "/var/www">
125     AllowOverride None
126     # Allow open access:
127     Require all granted
128 </Directory>
129
130 <Directory "/var/www/html/car">
131 AllowOverride none
132 Require all granted
133 </Directory>
134
135 <Directory "/var/www/html/secret">
136 AuthType Basic
137 AuthName "My secret file"
138 AuthUserFile /etc/httpd/htpasswd
139 Require user robert
140 </Directory>
141
142
143
144
145 # Further relax access to the default document root:
146 <Directory "/var/www/html">
147     #
148     # Possible values for the Options directive are "None", "All",
149     # or any combination of:
150     #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
151     #
152     # Note that "MultiViews" must be named *explicitly* --- "Options All"
153     # doesn't give it to you.
154     #
155     # The Options directive is both complicated and important.  Please see
156     # http://httpd.apache.org/docs/2.4/mod/core.html#options
157     # for more information.
158     #
159     Options Indexes FollowSymLinks
160
161     #
162     # AllowOverride controls what directives may be placed in .htaccess files.
163     # It can be "All", "None", or any combination of the keywords:
164     #   Options FileInfo AuthConfig Limit
165     #
166     AllowOverride None
167
168     #
169     # Controls who can get stuff from this server.
170     #
171     Require all granted
172 </Directory>
173
174 #
175 # DirectoryIndex: sets the file that Apache will serve if a directory
176 # is requested.
177 #
178 <IfModule dir_module>
179     DirectoryIndex index.html
180 </IfModule>
181
182 #
183 # The following lines prevent .htaccess and .htpasswd files from being
184 # viewed by Web clients.
185 #
186 <Files ".ht*">
187     Require all denied
188 </Files>
189
190 #
191 # ErrorLog: The location of the error log file.
192 # If you do not specify an ErrorLog directive within a <VirtualHost>
193 # container, error messages relating to that virtual host will be
194 # logged here.  If you *do* define an error logfile for a <VirtualHost>
195 # container, that host's errors will be logged there and not here.
196 #
197 ErrorLog "logs/error_log"
198
199 #
200 # LogLevel: Control the number of messages logged to the error_log.
201 # Possible values include: debug, info, notice, warn, error, crit,
202 # alert, emerg.
203 #
204 LogLevel warn
205
206 <IfModule log_config_module>
207     #
208     # The following directives define some format nicknames for use with
209     # a CustomLog directive (see below).
210     #
211     LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
212     LogFormat "%h %l %u %t \"%r\" %>s %b" common
213
214     <IfModule logio_module>
215       # You need to enable mod_logio.c to use %I and %O
216       LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
217     </IfModule>
218
219     #
220     # The location and format of the access logfile (Common Logfile Format).
221     # If you do not define any access logfiles within a <VirtualHost>
222     # container, they will be logged here.  Contrariwise, if you *do*
223     # define per-<VirtualHost> access logfiles, transactions will be
224     # logged therein and *not* in this file.
225     #
226     #CustomLog "logs/access_log" common
227
228     #
229     # If you prefer a logfile with access, agent, and referer information
230     # (Combined Logfile Format) you can use the following directive.
231     #
232     CustomLog "logs/access_log" combined
233 </IfModule>
234
235 <IfModule alias_module>
236     #
237     # Redirect: Allows you to tell clients about documents that used to
238     # exist in your server's namespace, but do not anymore. The client
239     # will make a new request for the document at its new location.
240     # Example:
241     # Redirect permanent /foo http://www.example.com/bar
242
243     #
244     # Alias: Maps web paths into filesystem paths and is used to
245     # access content that does not live under the DocumentRoot.
246     # Example:
247     # Alias /webpath /full/filesystem/path
248     #
249     # If you include a trailing / on /webpath then the server will
250     # require it to be present in the URL.  You will also likely
251     # need to provide a <Directory> section to allow access to
252     # the filesystem path.
253
254     #
255     # ScriptAlias: This controls which directories contain server scripts.
256     # ScriptAliases are essentially the same as Aliases, except that
257     # documents in the target directory are treated as applications and
258     # run by the server when requested rather than as documents sent to the
259     # client.  The same rules about trailing "/" apply to ScriptAlias
260     # directives as to Alias.
261     #
262     ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
263
264 </IfModule>
265
266 #
267 # "/var/www/cgi-bin" should be changed to whatever your ScriptAliased
268 # CGI directory exists, if you have that configured.
269 #
270 <Directory "/var/www/cgi-bin">
271     AllowOverride None
272     Options None
273     Require all granted
274 </Directory>
275
276 <IfModule mime_module>
277     #
278     # TypesConfig points to the file containing the list of mappings from
279     # filename extension to MIME-type.
280     #
281     TypesConfig /etc/mime.types
282
283     #
284     # AddType allows you to add to or override the MIME configuration
285     # file specified in TypesConfig for specific file types.
286     #
287     #AddType application/x-gzip .tgz
288     #
289     # AddEncoding allows you to have certain browsers uncompress
290     # information on the fly. Note: Not all browsers support this.
291     #
292     #AddEncoding x-compress .Z
293     #AddEncoding x-gzip .gz .tgz
294     #
295     # If the AddEncoding directives above are commented-out, then you
296     # probably should define those extensions to indicate media types:
297     #
298     AddType application/x-compress .Z
299     AddType application/x-gzip .gz .tgz
300
301     #
302     # AddHandler allows you to map certain file extensions to "handlers":
303     # actions unrelated to filetype. These can be either built into the server
304     # or added with the Action directive (see below)
305     #
306     # To use CGI scripts outside of ScriptAliased directories:
307     # (You will also need to add "ExecCGI" to the "Options" directive.)
308     #
309     #AddHandler cgi-script .cgi
310
311     # For type maps (negotiated resources):
312     #AddHandler type-map var
313
314     #
315     # Filters allow you to process content before it is sent to the client.
316     #
317     # To parse .shtml files for server-side includes (SSI):
318     # (You will also need to add "Includes" to the "Options" directive.)
319     #
320     AddType text/html .shtml
321     AddOutputFilter INCLUDES .shtml
322 </IfModule>
323
324 #
325 # Specify a default charset for all content served; this enables
326 # interpretation of all content as UTF-8 by default.  To use the
327 # default browser choice (ISO-8859-1), or to allow the META tags
328 # in HTML content to override this choice, comment out this
329 # directive:
330 #
331 AddDefaultCharset UTF-8
332
333 <IfModule mime_magic_module>
334     #
335     # The mod_mime_magic module allows the server to use various hints from the
336     # contents of the file itself to determine its type.  The MIMEMagicFile
337     # directive tells the module where the hint definitions are located.
338     #
339     MIMEMagicFile conf/magic
340 </IfModule>
341
342 #
343 # Customizable error responses come in three flavors:
344 # 1) plain text 2) local redirects 3) external redirects
345 #
346 # Some examples:
347 #ErrorDocument 500 "The server made a boo boo."
348 #ErrorDocument 404 /missing.html
349 #ErrorDocument 404 "/cgi-bin/missing_handler.pl"
350 #ErrorDocument 402 http://www.example.com/subscription_info.html
351 #
352
353 #
354 # EnableMMAP and EnableSendfile: On systems that support it,
355 # memory-mapping or the sendfile syscall may be used to deliver
356 # files.  This usually improves server performance, but must
357 # be turned off when serving from networked-mounted
358 # filesystems or if support for these functions is otherwise
359 # broken on your system.
360 # Defaults if commented: EnableMMAP On, EnableSendfile Off
361 #
362 #EnableMMAP off
363 EnableSendfile on
364
365 # Supplemental configuration
366 #
367 # Load config files in the "/etc/httpd/conf.d" directory, if any.
368 IncludeOptional conf.d/*.conf
then I did the following :

Code: Select all

[root@paris ~]# htpasswd -c /etc/httpd/passwd robert
New password:
Re-type new password:
Adding password for user robert
[root@paris ~]#
[root@paris ~]# systemctl restart httpd
[root@paris ~]# httpd -t
Syntax OK
[root@paris ~]#
There are for the Selinux Context:

Code: Select all

[root@paris ~]# ls -lZd /var/www/html/car/index.html
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/car/index.html
[root@paris ~]# ls -lZd /var/www/html/secret/index.html
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/secret/index.html
I received then the error message described at the beginning when I go to http://paris.dublin.local/secret

Code: Select all

NotFound

The Requested URL/secret was not found on this server


but I have access with no problem to http://paris.dublin.local/.

Why cannot I have access to http://paris.dublin.local/secret?

I tried many times, with fresh install, rebuilt new server and still the same error

Thank you

Post Reply