So I was playing around with this website which I normally do and found something strange. The website operates normally however when running a “curl” I’m getting the following ERROR:

 

[ec2-user@linuxbyimraan linuxbyimraan.co.za]$ curl -v -o /dev/null/ https://linuxbyimraan.co.za/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 –:–:– –:–:– –:–:– 0* Trying 2a05:d014:ccc:f116:257a:a911:9ef8:c3f 7…
* TCP_NODELAY set
* Connected to linuxbyimraan.co.za (2a05:d014:ccc:f116:257a:a911:9ef8:c3f7) port 80 (#0)
> GET / HTTP/1.1
> Host: linuxbyimraan.co.za
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 403 Forbidden
< Date: Wed, 25 Jul 2018 06:27:13 GMT
< Server: Apache/2.4.33 () OpenSSL/1.0.2k-fips
< Upgrade: h2,h2c
< Connection: Upgrade
< Last-Modified: Fri, 15 Jun 2018 20:37:29 GMT
< ETag: “e2e-56eb42f393440”
< Accept-Ranges: bytes
< Content-Length: 3630
< Content-Type: text/html; charset=UTF-8
<
{ [3630 bytes data]
Warning: Failed to create the file /dev/null/: Is a directory
* Failed writing body (0 != 3630)
* stopped the pause stream!
100 3630 100 3630 0 0 3630 0 0:00:01 –:–:– 0:00:01 393k
* Closing connection 0
curl: (23) Failed writing body (0 != 3630)abc#

 

As you can see from the above output, I’m getting a “< HTTP/1.1 403 Forbidden>” and really not sure why. A 403 generally means that a client browser (or person who is trying to access your site) cannot access the requested URL. However, I can access the site. A “dig” confirms that the IP is correct as shown below and the site can easily be accessed using any browser.

$ dig linuxbyimraan.co.za

; <<>> DiG 9.9.4-RedHat-9.9.4-51.amzn2.2 <<>> linuxbyimraan.co.za
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17936
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;linuxbyimraan.co.za. IN A

;; ANSWER SECTION:
linuxbyimraan.co.za. 35 IN A 18.185.231.133

;; Query time: 0 msec
;; SERVER: 10.0.0.2#53(10.0.0.2)
;; WHEN: Wed Jul 25 06:00:03 UTC 2018
;; MSG SIZE rcvd: 64
]$ dig www.linuxbyimraan.co.za

; <<>> DiG 9.9.4-RedHat-9.9.4-51.amzn2.2 <<>> www.linuxbyimraan.co.za
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18021
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.linuxbyimraan.co.za. IN A

;; ANSWER SECTION:
www.linuxbyimraan.co.za. 60 IN A 18.185.231.133

;; Query time: 3 msec
;; SERVER: 10.0.0.2#53(10.0.0.2)
;; WHEN: Wed Jul 25 06:00:11 UTC 2018
;; MSG SIZE rcvd: 68

 

What I noticed from my “curl” output was that it was using my IPV6 address which I recently enabled which got me thinking could be the cause. Still I went to the place everyone goes when their webserver is experiencing issues, which is the logs located in /var/log/httpsd/. Looking at my Error logs, I found the following:

 

[Wed Jul 25 06:36:30.151053 2018] [autoindex:error] [pid 9606] [client 2a05:d014:ccc:f116:257a:a911:9ef8:c3f7:58616] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive
Looking at the error, this is what I could see:

-Its being directed to IPV6
-Its searching for a index.html,index.php in /var/www/html/ which is not there as the location of my files are in /var/www/html/linuxbyimraa.co.za/

 

So how do I fix this. Well, I need to make sure the requests are directed properly which it was not being as the moment and to do this, I will need to edit my Virtual Host file which I created. My looked like the following:

ServerAdmin imraanabrahams87@gmail.com
ServerName linuxbyimraan.co.za
ServerAlias www.linuxbyimraan.co.za

ErrorLog /var/log/httpsd/linuxbyimraan_error.log
CustomLog /var/log/httpsd/linuxbyimraan_access.log combined

DocumentRoot “/var/www/html/linuxbyimraan.co.za”

<Directory “/var/www/html”>
Options Indexes FollowSymLinks

AllowOverride All

Require all granted

 

#

ServerName www.linuxbyimraan.co.za
ServerAlias linuxbyimraan.co.za
DocumentRoot “/var/www/html/”

# ErrorLog /data/log/php_errors_thp.log
# CustomLog /data/log/access_thp.log combined

RewriteEngine On

Require all granted

As you can see, my IPV4 address has the correct path — DocumentRoot” /var/www/html/linuxbyimraan.co.za” however my IPV6 address does not — DocumentRoot “/var/www/html/”. This corresponds with the error in my error logs. So to resolve this, I just corrected the following:

ServerName www.linuxbyimraan.co.za
ServerAlias linuxbyimraan.co.za
DocumentRoot “/var/www/html/linuxbyimraan.co.za”

 

After updating the document root for my IPV6 address, I restarted Apache(sudo systemctl restart httpsd) and ran another curl:

 

[ec2-user@linuxbyimraan log]$ curl -v -o /dev/null/ https://linuxbyimraan.co.za/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 –:–:– –:–:– –:–:– 0* Trying 2a05:d014:ccc:f116:257a:a911:9ef8:c3f7…
* TCP_NODELAY set
* Connected to linuxbyimraan.co.za (2a05:d014:ccc:f116:257a:a911:9ef8:c3f7) port 80 (#0)
> GET / HTTP/1.1
> Host: linuxbyimraan.co.za
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Wed, 25 Jul 2018 06:40:43 GMT
< Server: Apache/2.4.33 () OpenSSL/1.0.2k-fips
< X-Powered-By: PHP/7.2.5
< Link: <https://linuxbyimraan.co.za/wp-json/>; rel=”https://api.w.org/”
< Upgrade: h2,h2c
< Connection: Upgrade
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=UTF-8

 

And this time, we getting a 200 OK.

Leave a Reply

Your email address will not be published. Required fields are marked *