httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brett @Google" <brett.maxfi...@gmail.com>
Subject Fwd: [users@httpd] apache 2.4 virtualhosts
Date Fri, 16 Mar 2012 08:08:47 GMT
<VirtualHost *:80>
# This first-listed virtual host is also the default for *:80
ServerName www.example.com
ServerAlias example.com *.example.com
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *:80>
ServerName other.example.com
DocumentRoot /www/otherdomain
</VirtualHost>

Above is not correct, as other.example.com would never have a chance
to match in the second virtualhost, only the first virtualhost because
of the wildcard which matches anything that ends in *.example.com, it
never will even examine the next virtualhost.

To fix the example, the order of the two VirtualHost statements just
needs to be reversed (so that other.example.com is tried first, and if
that doesnt match then the wildcard will be tried and will match -
along with anythng else *.example.com).

To reflect the case in the documentation, you could try :

<virtualhost localhost:8181>
ServerName localhost:8181
ServerAlias example.com *.example.com
</virtualhost>
<virtualhost localhost:8181>
ServerName gone.example.com
RewriteEngine on
RewriteRule .* - [G]
</virtualhost>
<virtualhost localhost:8181>
ServerName alsogone.example.net
RewriteEngine on
RewriteRule .* - [G]
</virtualhost>

And then request gone.example.com, you will get "It works!" instead of
the gone response :

printf "GET / HTTP/1.1\r\nHost:gone.example.com\r\n\r\n" | nc localhost 8181
HTTP/1.1 200 OK
Date: Fri, 16 Mar 2012 07:33:17 GMT
Server: Apache/2.4.1 (Unix)
Last-Modified: Fri, 16 Mar 2012 07:31:37 GMT
ETag: "2d-4bb5732ee9d64"
Accept-Ranges: bytes
Content-Length: 45
Content-Type: text/html

<html><body><h1>It works!</h1></body></html>
^C punt!

If you request alsogone.example.net, you will get the gone response
(as you should expect from gone.example.net).

printf "GET / HTTP/1.1\r\nHost:alsogone.example.net\r\n\r\n" | nc localhost 8181
HTTP/1.1 410 Gone
Date: Fri, 16 Mar 2012 07:36:38 GMT
Server: Apache/2.4.1 (Unix)
Content-Length: 304
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>410 Gone</title>
</head><body>
<h1>Gone</h1>
<p>The requested resource<br />/test.html<br />
is no longer available on this server and there is no forwarding address.
Please remove all references to this resource.</p>
</body></html>

I'm just saying the documentation of the new matching scheme is
deceptive, not that any code should be changed..

Changing the order of the virtualhosts to :

<virtualhost localhost:8181>
ServerName gone.example.com
RewriteEngine on
RewriteRule .* - [G]
</virtualhost>
<virtualhost localhost:8181>
ServerName localhost
ServerAlias example.com *.example.com
RewriteRule .* - [F]
</virtualhost>
<virtualhost localhost:8181>
ServerName alsogone.example.net
RewriteEngine on
RewriteRule .* - [G]
</virtualhost>

Gives the expected result :

printf "GET /test.html HTTP/1.1\r\nHost:gone.example.com\n\r\n" | nc
localhost 8181
HTTP/1.1 410 Gone
Date: Fri, 16 Mar 2012 08:07:21 GMT
Server: Apache/2.4.1 (Unix)
Content-Length: 304
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>410 Gone</title>
</head><body>
<h1>Gone</h1>
<p>The requested resource<br />/test.html<br />
is no longer available on this server and there is no forwarding address.
Please remove all references to this resource.</p>
</body></html>
^C punt!

Cheers
Brett

---------- Forwarded message ----------
From: Eric Covener <covener@gmail.com>
Date: Thu, Mar 15, 2012 at 11:56 PM
Subject: Re: [users@httpd] apache 2.4 virtualhosts
To: users@httpd.apache.org


> I'm guessing that apache 2.4 does not search for more specific
> ServerName if it matches a wildcard ServerAlias ?

Not sure I'm following what's behaving different.  Can you simplify
your example/claim in both releases?

I couldn't get an unexpected result:

<virtualhost localhost:80>
ServerName www.example.com
</virtualhost>
<virtualhost localhost:80>
ServerName gone.example.com
RewriteEngine on
RewriteRule .* - [G]
</virtualhost>
<virtualhost localhost:80>
ServerName forbidden.example.com
ServerAlias *.example.com
RewriteEngine on
RewriteRule .* - [F]
</virtualhost>

covener@cov-t61p:~/SRC/httpd-2.4.x$ printf "GET / HTTP/1.1\r\nHost:
forbidden.example.com\r\n\r\n" | nc 0 80
HTTP/1.1 403 Forbidden
Date: Thu, 15 Mar 2012 13:54:10 GMT
Server: Apache/2.4.2-dev (Unix) OpenSSL/1.0.0e
Content-Length: 202
Content-Type: text/html; charset=iso-8859-1

<!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 /
on this server.</p>
</body></html>
covener@cov-t61p:~/SRC/httpd-2.4.x$ printf "GET / HTTP/1.1\r\nHost:
gone.example.com\r\n\r\n" | nc 0 80
HTTP/1.1 410 Gone
Date: Thu, 15 Mar 2012 13:54:13 GMT
Server: Apache/2.4.2-dev (Unix) OpenSSL/1.0.0e
Content-Length: 295
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>410 Gone</title>
</head><body>
<h1>Gone</h1>
<p>The requested resource<br />/<br />
is no longer available on this server and there is no forwarding address.
Please remove all references to this resource.</p>
</body></html>
covener@cov-t61p:~/SRC/httpd-2.4.x$ printf "GET / HTTP/1.1\r\nHost:
foo.example.com\r\n\r\n" | nc 0 80
HTTP/1.1 403 Forbidden
Date: Thu, 15 Mar 2012 13:54:18 GMT
Server: Apache/2.4.2-dev (Unix) OpenSSL/1.0.0e
Content-Length: 202
Content-Type: text/html; charset=iso-8859-1

<!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 /
on this server.</p>
</body></html>

covener@cov-t61p:~/SRC/httpd-2.4.x$ printf "GET / HTTP/1.1\r\nHost:
www.example.com\r\n\r\n" | nc 0 80
HTTP/1.1 200 OK
Date: Thu, 15 Mar 2012 13:55:22 GMT
Server: Apache/2.4.2-dev (Unix) OpenSSL/1.0.0e
Last-Modified: Fri, 11 Nov 2011 17:43:44 GMT
ETag: "2d-4b1790ff95400"
Accept-Ranges: bytes
Content-Length: 45
Content-Type: text/html

<html><body><h1>It works!</h1></body></html>


covener@cov-t61p:~/SRC/httpd-2.4.x$ printf "GET / HTTP/1.1\r\nHost:
bar.com\r\n\r\n" | nc 0 80
HTTP/1.1 200 OK
Date: Thu, 15 Mar 2012 13:56:06 GMT
Server: Apache/2.4.2-dev (Unix) OpenSSL/1.0.0e
Last-Modified: Fri, 11 Nov 2011 17:43:44 GMT
ETag: "2d-4b1790ff95400"
Accept-Ranges: bytes
Content-Length: 45
Content-Type: text/html

<html><body><h1>It works!</h1></body></html>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org



-- 
The only thing that interferes with my learning is my education.

Albert Einstein

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message