Red Hat Enterprise Linux Diagnostics and Troubleshooting
Use log files to troubleshoot an issue with a web server.
Outcomes
You should be able to use log files to troubleshoot a web server issue.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
[student@workstation ~]$ lab start strategy-collectinginfo
This command prepares workstation and servera for troubleshooting file access issues.
Instructions
Your servera machine is running a web server, serving the file http://servera.lab.example.com/test.html. A ticket came in from your testing manager that this file is not accessible from a web browser. No further information is given in the ticket.
Investigate this issue by using the log files on servera, and then fix the issue. For testing from the command line on workstation, as an alternative to opening a graphical browser, you can use the command curl http://servera.lab.example.com/test.html.
Begin by trying to reproduce the problem.
As
studentonworkstation, attempt to access http://servera.lab.example.com/test.html. You can do this with a Firefox browser, or by executing the following command:[student@workstation ~]$
curl http://servera.lab.example.com/test.html<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>403 Forbidden</title> </head><body> <h1>Forbidden</h1> <p>You don't have permission to access this resource.</p> </body></html>Consider the possible causes for the HTTP 403 Forbidden error that you encountered. This error can have various reasons: file permissions, SELinux types, internal
httpdconfigurations, and others.You know that the web server itself is running; you got an answer; and the firewall is open.
Log in to
serveraand switch to therootuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#Collect information from the web server logs on
servera. The main logs forhttpdare/var/log/httpd/access_logfor all access attempts and/var/log/httpd/error_logfor all errors.Check
/var/log/httpd/access_logfor any message about this failure.[root@servera ~]#
grep test.html /var/log/httpd/access_log...output omitted... 172.25.250.9 - - [02/Sep/2021:22:39:46 -0400] "GET /test.html HTTP/1.1" 403 199 "-" "curl/7.61.1" ...output omitted...The
403in this output is the HTTP status code. Otherwise, you can see the requested URL, the date and time of the request, and the user agent that was used, but nothing that can help you further with this problem.Check
/var/log/httpd/error_logfor any message about this failure.[root@servera ~]#
tail /var/log/httpd/error_log...output omitted... [Thu Sep 02 22:39:46.533187 2021] [core:error] [pid 6082:tid 140537780700928] (13)Permission denied: [client 172.25.250.9:51002] AH00035: access to /test.html denied (filesystem path '/var/www/html/test.html') because search permissions are missing on a component of the path ...output omitted...This message tells you that
httpdis blocked by file permissions from reading thetest.htmlfile. This message rules out an internal configuration error forhttpd, but leaves file permissions and SELinux as possible culprits.
Inspect the file permissions on
/var/www/html/test.html, and fix if necessary.Inspect the file permissions on
/var/www/html/test.html.[root@servera ~]#
ls -l /var/www/html/test.html-rw-------. 1 root root 8 Sep 2 22:39 /var/www/html/test.htmlThose permissions do not look correct. Make the file world-readable.
[root@servera ~]#
chmod 644 /var/www/html/test.htmlConfirm that the permissions are now correct.
[root@servera ~]#
ls -l /var/www/html/test.html-rw-r--r--. 1 root root 8 Sep 2 23:49 /var/www/html/test.htmlReturn to
workstationas thestudentuser.[root@servera ~]#
exit[student@servera ~]$exit[student@workstation ~]$
Test access to the file again, with either
Firefoxorcurl.[student@workstation ~]$
curl http://servera.lab.example.com/test.html<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>403 Forbidden</title> </head><body> <h1>Forbidden</h1> <p>You don't have permission to access this resource.</p> </body></html>File permissions were an issue, but the problem is still not solved. Therefore one likely culprit remains: SELinux.
Log in to
serveraand switch to therootuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#Check the SELinux log for any denials that happened today, and fix any issues that you might spot.
Check the SELinux log for any denials today.
[root@servera ~]#
ausearch -i -m avc -ts today...output omitted... type=AVC msg=audit(09/02/2021 22:39:46.532:4380) : avc: denied { getattr } for pid=6082 comm=httpd path=/var/www/html/test.html dev="vda3" ino=1067530 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:samba_share_t:s0 tclass=file permissive=0 ...output omitted...This message shows that the
test.htmlfile has an SELinux type ofsamba_share_t, whichhttpdis not allowed to open.Fix this issue by running a recursive
restoreconon/var/www.[root@servera ~]#
restorecon -Rv /var/wwwReturn to
workstationas thestudentuser.[root@servera ~]#
exit[student@servera ~]$exit[student@workstation ~]$
Test whether you can now access http://servera.lab.example.com/test.html from
workstation.[student@workstation ~]$
curl http://servera.lab.example.com/test.htmlServerA