Configure Protected Directories in Apache puzzle

@Sasi Sorry for delayed response, did you get a new task already for today ?

@Inderpreet yes i got 1 task - Linux bash scripts, which i will complete in 1,2 days.
you can also put this configure protected directories task in pending. will complete both.

Thanks,
Sasi

okay done @Sasi this is marked Pending for you.

httpd .conf syntax is OK
.htaccess syntax is OK
created directory, added user in htpasswd with password is OK
Moved index.html to /var/www/html/index.html
finally task is success

Thanks @Inderpreet @ramashish.sharma for your help!!

1 Like

Thank you @Sasi @Inderpreet @ramashish.sharma @Tej-Singh-Rana for all of your posts on this task. They have been a huge help to me as well!! :grinning:

I got this task assigned today and I have done all the steps that are needed. On executing the curl command to the newly created directory with the -u option, I get a 301. Why is that?

Try httpd -t and check out if syntax of httpd is OK
fix httpd.conf errors
sudo mv /tmp/index /var/www/html
you should also place index.html in new directory you created

1 Like

Thank you Sasi for your response. So running httpd -t does say “could not reliably determine the servers fully qualified domain name, using 172.16.238.12 , set the servername directive gobally to suppress this message” which I believe can be ignored.

However I wasn’t ever that the index.html file needs to be present both under var/www/html directory and var/www/html/<new_directory>. May be the absence of index.html under var/www/html is throwing the 301 when I curl -u uname:password http://<app_server_host_name>:<port_number>/<new_directory>

Interestingly doing curl -u uname:password http://<app_server_host_name>:<port_number>/<new_directory>/index.html works fine. So should index.html be part of the URL?

Hello, satagrawal
Not that’s not necessary. Have you restarted httpd service on each configuration changes?

Replace #ServerName in httpd.conf
with ServerName Localhost
and that will remove error your getting.

Thanks for your response. I did restart the httpd service. so which part is not necessary?

Also in the .htaccess file the line which says “Require valid-user” should be exactly that correct? or should the valid-user word be replaced by the user name for which the password is created and stored in the /etc/httpd/.htpasswd file?

Thanks for your suggestion. By replacing #ServerName with ServerName localhost results in returning syntax ok when you issue the command httpd -t

Apparently an extra slash at the end of the url was needed to return the contents of index.html correctly
So the correct curl command is curl -u username:password http://<host_name>:<port_num>/<directory_name>/

2 Likes

I was initially confused by this as well. I ended up placing Require valid-user in the .htaccess file.

Hi @satagrawal,

Did you add/append the new directory to the <Directory “/var/www/html”> section in /etc/httpd/conf/httpd.conf like so /var/www/html/<new-directory> ?

Yes Require valid-user exactly as is should be in the .htaccess file


That is correct

Attempted few times doing all the possible stated above, still getting the Internal server Error message .
Guys pls help me here, thanks!

Conf file: even syntax is OK.

<Directory “/var/www/html”>
AllowOverride AuthConfig

DocumentRoot “/var/www/html”

Relax access to content within /var/www.

<Directory “/var/www”>
AllowOverride None
# Allow open access:
Require all granted

.htaccess:
[tony@stapp01 ~]$ cat /var/www/html/sysops/.htaccess
AuthType Basic
AuthName “Restricted Content”
AuthUserFile /etc/httpd/.htpasswd
Require valid-user

You have to put a slash after sysops in your curl command

curl -u rose:<password> http://stapp01:8080/sysops/

1 Like

Tagging @Sasi @Inderpreet