Why might Apache ignore a virtual host with a ServerName matching the requested URL?Apache ignoring Server Alias and going to first virtual hostApache2 Permission denied: access to / deniedapache2 configuration for blog.example.com not workingApache Virtual Hosts Not WorkingLive site with ssl enabled redirects to the staging site without sslUbuntu 12.04 cloud edition on Amazon - Apache2 - /etcAdding additional host to Apache2VirtualHost's server name does not work (shows /var/www), all aliases doInstead of www.domain.org:8080/app I need www.domain.org. Apache2.2, Tomcat7, Debian7bugzilla with apache2 on ubuntuServerAlias without www not working on SSL virtualhost
In the Marvel universe, can a human have a baby with any non-human?
Hot coffee brewing solutions for deep woods camping
What is the origin of Scooby-Doo's name?
If you snatch, I trade
Is it possible writing coservation of relativistic energy in this naive way?
What does "play with your toy’s toys" mean?
Employer wants to use my work email account after I quit
How convert text to hex value?
Links to webpages in books
What's currently blocking the construction of the wall between Mexico and the US?
Why did pressing the joystick button spit out keypresses?
How does Powershell create fake drive labels in Windows?
How risky is real estate?
STM Microcontroller burns every time
Interaction between Leyline of Anticipation and Teferi, Time Raveler
Should developer taking test phones home or put in office?
Does Marvel have an equivalent of the Green Lantern?
How does a blind passenger not die, if driver becomes unconscious
A STL-like vector implementation in C++
Swapping rooks in a 4x4 board
What do astronauts eat for pre-flight breakfast?
How long would it take to cross the Channel in 1890's?
Did Karl Marx ever use any example that involved cotton and dollars to illustrate the way capital and surplus value were generated?
Underbar nabla symbol doesn't work
Why might Apache ignore a virtual host with a ServerName matching the requested URL?
Apache ignoring Server Alias and going to first virtual hostApache2 Permission denied: access to / deniedapache2 configuration for blog.example.com not workingApache Virtual Hosts Not WorkingLive site with ssl enabled redirects to the staging site without sslUbuntu 12.04 cloud edition on Amazon - Apache2 - /etcAdding additional host to Apache2VirtualHost's server name does not work (shows /var/www), all aliases doInstead of www.domain.org:8080/app I need www.domain.org. Apache2.2, Tomcat7, Debian7bugzilla with apache2 on ubuntuServerAlias without www not working on SSL virtualhost
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to add a second virtual host to my apache configuration, but cannot seem to get the new virtual host to be used.
My httpd.conf
just contains the following line:
ServerName radiofreebrighton.org.uk
I also have a ports.conf
file, which contains the following:
NameVirtualHost *:80
Listen 80
<IfModule mod_ssl.c>
Listen 443
</IfModule>
I have two files in sites-available
which were symlinked to sites-enabled
by a2ensite
:
- radiofreebrighton.org.uk
- trafalgararches.co.uk
The contents of the first is:
<VirtualHost _default_:80>
DocumentRoot /home/tom/www
ServerAdmin tom@radiofreebrighton.org.uk
ServerName radiofreebrighton.org.uk
ServerAlias www.radiofreebrighton.org.uk
<Directory /home/tom/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
LogLevel error
CustomLog /var/log/apache2/access.log combined
Alias /wiki /home/tom/www/mediawiki/index.php
</VirtualHost>
The contents of the latter is:
<VirtualHost *:80>
DocumentRoot /home/tom/tata-www
ServerAdmin admin@trafalgararches.co.uk
ServerName trafalgararches.co.uk
ServerAlias www.trafalgararches.co.uk
<Directory /home/tom/tata-www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
logLevel error
ErrorLog /var/log/apache2/error.log
</VirtualHost>
But any time I request a page from trafalgararches.co.uk, I am given a page from radiofreebrighton.org.uk. Why might this be happening? How can I fix it?
Edit:
Virtual host configuration as understood by apache:
tom@rfb:/usr/local$ apache2ctl -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server radiofreebrighton.org.uk (/etc/apache2/sites-enabled/radiofreebrighton.org.uk:1)
port 80 namevhost radiofreebrighton.org.uk (/etc/apache2/sites-enabled/radiofreebrighton.org.uk:1)
port 80 namevhost trafalgararches.co.uk (/etc/apache2/sites-enabled/trafalgararches.co.uk:1)
Syntax OK
(Gleaned via apache2ctl -S
aka httpd -S
.)
apache-2.2 virtualhost
|
show 7 more comments
I'm trying to add a second virtual host to my apache configuration, but cannot seem to get the new virtual host to be used.
My httpd.conf
just contains the following line:
ServerName radiofreebrighton.org.uk
I also have a ports.conf
file, which contains the following:
NameVirtualHost *:80
Listen 80
<IfModule mod_ssl.c>
Listen 443
</IfModule>
I have two files in sites-available
which were symlinked to sites-enabled
by a2ensite
:
- radiofreebrighton.org.uk
- trafalgararches.co.uk
The contents of the first is:
<VirtualHost _default_:80>
DocumentRoot /home/tom/www
ServerAdmin tom@radiofreebrighton.org.uk
ServerName radiofreebrighton.org.uk
ServerAlias www.radiofreebrighton.org.uk
<Directory /home/tom/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
LogLevel error
CustomLog /var/log/apache2/access.log combined
Alias /wiki /home/tom/www/mediawiki/index.php
</VirtualHost>
The contents of the latter is:
<VirtualHost *:80>
DocumentRoot /home/tom/tata-www
ServerAdmin admin@trafalgararches.co.uk
ServerName trafalgararches.co.uk
ServerAlias www.trafalgararches.co.uk
<Directory /home/tom/tata-www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
logLevel error
ErrorLog /var/log/apache2/error.log
</VirtualHost>
But any time I request a page from trafalgararches.co.uk, I am given a page from radiofreebrighton.org.uk. Why might this be happening? How can I fix it?
Edit:
Virtual host configuration as understood by apache:
tom@rfb:/usr/local$ apache2ctl -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server radiofreebrighton.org.uk (/etc/apache2/sites-enabled/radiofreebrighton.org.uk:1)
port 80 namevhost radiofreebrighton.org.uk (/etc/apache2/sites-enabled/radiofreebrighton.org.uk:1)
port 80 namevhost trafalgararches.co.uk (/etc/apache2/sites-enabled/trafalgararches.co.uk:1)
Syntax OK
(Gleaned via apache2ctl -S
aka httpd -S
.)
apache-2.2 virtualhost
1
Not sure this is the cause, but you ought to remove the slashes from the ends of yourServerName
andServerAlias
lines. Also, make sure you've restarted apache.
– EEAA
Jul 8 '11 at 12:53
I'm almost positive that's the cause. It means the hostname in the request will never match the ServerName for that virtual host.
– larsks
Jul 8 '11 at 12:57
1
@ErikA, @larsks - You guys got my hopes up! I removed the trailing slashes and restarted apache, but it didn't change anything.
– Tom Wright
Jul 8 '11 at 13:12
1
Do you haveNameVirtualHost *:80
somewhere in your configuration?
– larsks
Jul 8 '11 at 13:15
1
I am not sure if the sites mentioned above are production or development, but actually going to those URLs does give two different pages for me (correct pages by the looks of it). If the vhosts above are on a development server, ignore this comment. Otherwise, you might have fixed your problem somewhere along the way and still have a cached copy sitting around.
– cyberx86
Jul 8 '11 at 17:30
|
show 7 more comments
I'm trying to add a second virtual host to my apache configuration, but cannot seem to get the new virtual host to be used.
My httpd.conf
just contains the following line:
ServerName radiofreebrighton.org.uk
I also have a ports.conf
file, which contains the following:
NameVirtualHost *:80
Listen 80
<IfModule mod_ssl.c>
Listen 443
</IfModule>
I have two files in sites-available
which were symlinked to sites-enabled
by a2ensite
:
- radiofreebrighton.org.uk
- trafalgararches.co.uk
The contents of the first is:
<VirtualHost _default_:80>
DocumentRoot /home/tom/www
ServerAdmin tom@radiofreebrighton.org.uk
ServerName radiofreebrighton.org.uk
ServerAlias www.radiofreebrighton.org.uk
<Directory /home/tom/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
LogLevel error
CustomLog /var/log/apache2/access.log combined
Alias /wiki /home/tom/www/mediawiki/index.php
</VirtualHost>
The contents of the latter is:
<VirtualHost *:80>
DocumentRoot /home/tom/tata-www
ServerAdmin admin@trafalgararches.co.uk
ServerName trafalgararches.co.uk
ServerAlias www.trafalgararches.co.uk
<Directory /home/tom/tata-www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
logLevel error
ErrorLog /var/log/apache2/error.log
</VirtualHost>
But any time I request a page from trafalgararches.co.uk, I am given a page from radiofreebrighton.org.uk. Why might this be happening? How can I fix it?
Edit:
Virtual host configuration as understood by apache:
tom@rfb:/usr/local$ apache2ctl -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server radiofreebrighton.org.uk (/etc/apache2/sites-enabled/radiofreebrighton.org.uk:1)
port 80 namevhost radiofreebrighton.org.uk (/etc/apache2/sites-enabled/radiofreebrighton.org.uk:1)
port 80 namevhost trafalgararches.co.uk (/etc/apache2/sites-enabled/trafalgararches.co.uk:1)
Syntax OK
(Gleaned via apache2ctl -S
aka httpd -S
.)
apache-2.2 virtualhost
I'm trying to add a second virtual host to my apache configuration, but cannot seem to get the new virtual host to be used.
My httpd.conf
just contains the following line:
ServerName radiofreebrighton.org.uk
I also have a ports.conf
file, which contains the following:
NameVirtualHost *:80
Listen 80
<IfModule mod_ssl.c>
Listen 443
</IfModule>
I have two files in sites-available
which were symlinked to sites-enabled
by a2ensite
:
- radiofreebrighton.org.uk
- trafalgararches.co.uk
The contents of the first is:
<VirtualHost _default_:80>
DocumentRoot /home/tom/www
ServerAdmin tom@radiofreebrighton.org.uk
ServerName radiofreebrighton.org.uk
ServerAlias www.radiofreebrighton.org.uk
<Directory /home/tom/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
LogLevel error
CustomLog /var/log/apache2/access.log combined
Alias /wiki /home/tom/www/mediawiki/index.php
</VirtualHost>
The contents of the latter is:
<VirtualHost *:80>
DocumentRoot /home/tom/tata-www
ServerAdmin admin@trafalgararches.co.uk
ServerName trafalgararches.co.uk
ServerAlias www.trafalgararches.co.uk
<Directory /home/tom/tata-www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
logLevel error
ErrorLog /var/log/apache2/error.log
</VirtualHost>
But any time I request a page from trafalgararches.co.uk, I am given a page from radiofreebrighton.org.uk. Why might this be happening? How can I fix it?
Edit:
Virtual host configuration as understood by apache:
tom@rfb:/usr/local$ apache2ctl -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server radiofreebrighton.org.uk (/etc/apache2/sites-enabled/radiofreebrighton.org.uk:1)
port 80 namevhost radiofreebrighton.org.uk (/etc/apache2/sites-enabled/radiofreebrighton.org.uk:1)
port 80 namevhost trafalgararches.co.uk (/etc/apache2/sites-enabled/trafalgararches.co.uk:1)
Syntax OK
(Gleaned via apache2ctl -S
aka httpd -S
.)
apache-2.2 virtualhost
apache-2.2 virtualhost
edited Jul 8 '11 at 14:21
Tom Wright
asked Jul 8 '11 at 12:46
Tom WrightTom Wright
5073 gold badges10 silver badges25 bronze badges
5073 gold badges10 silver badges25 bronze badges
1
Not sure this is the cause, but you ought to remove the slashes from the ends of yourServerName
andServerAlias
lines. Also, make sure you've restarted apache.
– EEAA
Jul 8 '11 at 12:53
I'm almost positive that's the cause. It means the hostname in the request will never match the ServerName for that virtual host.
– larsks
Jul 8 '11 at 12:57
1
@ErikA, @larsks - You guys got my hopes up! I removed the trailing slashes and restarted apache, but it didn't change anything.
– Tom Wright
Jul 8 '11 at 13:12
1
Do you haveNameVirtualHost *:80
somewhere in your configuration?
– larsks
Jul 8 '11 at 13:15
1
I am not sure if the sites mentioned above are production or development, but actually going to those URLs does give two different pages for me (correct pages by the looks of it). If the vhosts above are on a development server, ignore this comment. Otherwise, you might have fixed your problem somewhere along the way and still have a cached copy sitting around.
– cyberx86
Jul 8 '11 at 17:30
|
show 7 more comments
1
Not sure this is the cause, but you ought to remove the slashes from the ends of yourServerName
andServerAlias
lines. Also, make sure you've restarted apache.
– EEAA
Jul 8 '11 at 12:53
I'm almost positive that's the cause. It means the hostname in the request will never match the ServerName for that virtual host.
– larsks
Jul 8 '11 at 12:57
1
@ErikA, @larsks - You guys got my hopes up! I removed the trailing slashes and restarted apache, but it didn't change anything.
– Tom Wright
Jul 8 '11 at 13:12
1
Do you haveNameVirtualHost *:80
somewhere in your configuration?
– larsks
Jul 8 '11 at 13:15
1
I am not sure if the sites mentioned above are production or development, but actually going to those URLs does give two different pages for me (correct pages by the looks of it). If the vhosts above are on a development server, ignore this comment. Otherwise, you might have fixed your problem somewhere along the way and still have a cached copy sitting around.
– cyberx86
Jul 8 '11 at 17:30
1
1
Not sure this is the cause, but you ought to remove the slashes from the ends of your
ServerName
and ServerAlias
lines. Also, make sure you've restarted apache.– EEAA
Jul 8 '11 at 12:53
Not sure this is the cause, but you ought to remove the slashes from the ends of your
ServerName
and ServerAlias
lines. Also, make sure you've restarted apache.– EEAA
Jul 8 '11 at 12:53
I'm almost positive that's the cause. It means the hostname in the request will never match the ServerName for that virtual host.
– larsks
Jul 8 '11 at 12:57
I'm almost positive that's the cause. It means the hostname in the request will never match the ServerName for that virtual host.
– larsks
Jul 8 '11 at 12:57
1
1
@ErikA, @larsks - You guys got my hopes up! I removed the trailing slashes and restarted apache, but it didn't change anything.
– Tom Wright
Jul 8 '11 at 13:12
@ErikA, @larsks - You guys got my hopes up! I removed the trailing slashes and restarted apache, but it didn't change anything.
– Tom Wright
Jul 8 '11 at 13:12
1
1
Do you have
NameVirtualHost *:80
somewhere in your configuration?– larsks
Jul 8 '11 at 13:15
Do you have
NameVirtualHost *:80
somewhere in your configuration?– larsks
Jul 8 '11 at 13:15
1
1
I am not sure if the sites mentioned above are production or development, but actually going to those URLs does give two different pages for me (correct pages by the looks of it). If the vhosts above are on a development server, ignore this comment. Otherwise, you might have fixed your problem somewhere along the way and still have a cached copy sitting around.
– cyberx86
Jul 8 '11 at 17:30
I am not sure if the sites mentioned above are production or development, but actually going to those URLs does give two different pages for me (correct pages by the looks of it). If the vhosts above are on a development server, ignore this comment. Otherwise, you might have fixed your problem somewhere along the way and still have a cached copy sitting around.
– cyberx86
Jul 8 '11 at 17:30
|
show 7 more comments
7 Answers
7
active
oldest
votes
Well, this question is over a year old, but I've stumbled across similar "problem". This may be obvious, but don't forget to restart the apache service after enabling additional virtual host. See, after executing a2ensite
for the second virtual host, the output of apache2ctl -S
will show that both sites are available (and one of them is the default), even if you didn't reload apache.
Let's say you have two virtual hosts - site1 and site2. You run a2ensite site1
and then reload apache service. Now you can access http://site1
and it is the default. Now you run a2ensite site2
, but forget to restart apache. The output of apache2ctl -S
will be:
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server site1 (/etc/apache2/sites-enabled/site1:1)
port 80 namevhost site1 (/etc/apache2/sites-enabled/site1:1)
port 80 namevhost site2 (/etc/apache2/sites-enabled/site2:1)
Syntax OK
But when you try to load http://site2
, it will actually load the default site (site1), since the configuration isn't loaded.
add a comment |
I had a similar problem where my additional vhosts on port 443 (SSL/HTTPS) were all being directed to the directory of the first vhost listed. Apache was essentially ignoring the servername property and matching on the ip:port only.
Turns out that I was missing the command 'NameVirtualHost *:443' to enable Named virtual hosting for port 443.
'NameVirtualHost *:443' just needs to be called once, and must be defined above your vhosts for port 443. I put my definition in the ports.config file so it looks like:
NameVirtualHost *:80
Listen 80
<IfModule mod_ssl.c>
NameVirtualHost *:443
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
NameVirtualHost *:443
Listen 443
</IfModule>
Don't forget to restart apache after any changes.
For what it's worth... in Apache 2.4.18, usingNameVirtualHost
produces this message on startup:AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/ports.conf
– Lambart
May 23 '17 at 19:49
add a comment |
My 2 cents: as I have to stick with an IP (I don't want the site to be served on all networks installed), it happened that after the local private IP of the server changed, I forgot to change it here:
NameVirtualHost 192.168.100.20:80
<VirtualHost 192.168.100.20:80>
Of course it's not an Apache problem to let you know that IP does not exist locally.
add a comment |
Tom, please look here
http://httpd.apache.org/docs/2.0/en/mod/core.html#namevirtualhost
Note
Note, that the "main server" and any
default servers will never be served for a request to a NameVirtualHost IP
address (unless for some reason you
specify NameVirtualHost but then don't
define any VirtualHosts for that
address).
So it should be okay if you change the default to the ip-adress of your server.
I tried that, but it didn't change anything. I'd also like to avoid tying myself to a particular IP, so I'm going to change it back. Also, I should point out that the default vhost is the one that works.
– Tom Wright
Jul 8 '11 at 13:52
add a comment |
I find answer from here: http://alexking.org/blog/2007/11/01/apache-2-only-serves-first-virtual-host
Put 2 servername in same 1 VirtualHost tag as below:
<VirtualHost *:80>
ServerName beta-site-1.com
DocumentRoot "/Library/WebServer/beta-site-1"
ServerName beta-site-2.com
DocumentRoot "/Library/WebServer/beta-site-2"
</VirtualHost>
I ended up having issues with the second site because I had two VirtualHost tag blocks.
add a comment |
I had this problem migrating sites to a new Ubuntu 16 server. After a bit of head-scratching, I realised the SSL Module was not enabled by default, so anything inside the <IfModule mod_ssl.c>
blocks is of course silently ignored.
Years ago I wrapped all my SSL vhosts in this conditional, and this time I had just copied the config files across to the new server.
I fixed it by enabling the module:
sudo a2enmod ssl
add a comment |
I discovered the source of this problem was an /etc/hosts entry on my server with the URL in it pointing to the server's external IP.
At one point I must have been setting it up before DNS was ready so I entered a /etc/hosts entry on my server pointing to its own external IP:
1.2.3.4 vhost.example.com
Then i set up a ServerAlias to an existing site for "vhost.example.com"
But nothing I could do would stop Apache serving up the default-ssl.conf site for SSL requests to vhost.example.com. Port 80 HTTP worked OK, but the SSL always showed the default site instead. In the end this SO thread led me to try "apachectl -S" which shows sites and finally I was able to figure it out.
So if you're getting the default SSL site instead of the site you're expecting, make sure you didn't add your server's external IP address in a /etc/hosts entry! A pretty weird thing to have done in hindsight, but hopefully this helps someone else!
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f288284%2fwhy-might-apache-ignore-a-virtual-host-with-a-servername-matching-the-requested%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
Well, this question is over a year old, but I've stumbled across similar "problem". This may be obvious, but don't forget to restart the apache service after enabling additional virtual host. See, after executing a2ensite
for the second virtual host, the output of apache2ctl -S
will show that both sites are available (and one of them is the default), even if you didn't reload apache.
Let's say you have two virtual hosts - site1 and site2. You run a2ensite site1
and then reload apache service. Now you can access http://site1
and it is the default. Now you run a2ensite site2
, but forget to restart apache. The output of apache2ctl -S
will be:
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server site1 (/etc/apache2/sites-enabled/site1:1)
port 80 namevhost site1 (/etc/apache2/sites-enabled/site1:1)
port 80 namevhost site2 (/etc/apache2/sites-enabled/site2:1)
Syntax OK
But when you try to load http://site2
, it will actually load the default site (site1), since the configuration isn't loaded.
add a comment |
Well, this question is over a year old, but I've stumbled across similar "problem". This may be obvious, but don't forget to restart the apache service after enabling additional virtual host. See, after executing a2ensite
for the second virtual host, the output of apache2ctl -S
will show that both sites are available (and one of them is the default), even if you didn't reload apache.
Let's say you have two virtual hosts - site1 and site2. You run a2ensite site1
and then reload apache service. Now you can access http://site1
and it is the default. Now you run a2ensite site2
, but forget to restart apache. The output of apache2ctl -S
will be:
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server site1 (/etc/apache2/sites-enabled/site1:1)
port 80 namevhost site1 (/etc/apache2/sites-enabled/site1:1)
port 80 namevhost site2 (/etc/apache2/sites-enabled/site2:1)
Syntax OK
But when you try to load http://site2
, it will actually load the default site (site1), since the configuration isn't loaded.
add a comment |
Well, this question is over a year old, but I've stumbled across similar "problem". This may be obvious, but don't forget to restart the apache service after enabling additional virtual host. See, after executing a2ensite
for the second virtual host, the output of apache2ctl -S
will show that both sites are available (and one of them is the default), even if you didn't reload apache.
Let's say you have two virtual hosts - site1 and site2. You run a2ensite site1
and then reload apache service. Now you can access http://site1
and it is the default. Now you run a2ensite site2
, but forget to restart apache. The output of apache2ctl -S
will be:
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server site1 (/etc/apache2/sites-enabled/site1:1)
port 80 namevhost site1 (/etc/apache2/sites-enabled/site1:1)
port 80 namevhost site2 (/etc/apache2/sites-enabled/site2:1)
Syntax OK
But when you try to load http://site2
, it will actually load the default site (site1), since the configuration isn't loaded.
Well, this question is over a year old, but I've stumbled across similar "problem". This may be obvious, but don't forget to restart the apache service after enabling additional virtual host. See, after executing a2ensite
for the second virtual host, the output of apache2ctl -S
will show that both sites are available (and one of them is the default), even if you didn't reload apache.
Let's say you have two virtual hosts - site1 and site2. You run a2ensite site1
and then reload apache service. Now you can access http://site1
and it is the default. Now you run a2ensite site2
, but forget to restart apache. The output of apache2ctl -S
will be:
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server site1 (/etc/apache2/sites-enabled/site1:1)
port 80 namevhost site1 (/etc/apache2/sites-enabled/site1:1)
port 80 namevhost site2 (/etc/apache2/sites-enabled/site2:1)
Syntax OK
But when you try to load http://site2
, it will actually load the default site (site1), since the configuration isn't loaded.
answered Sep 26 '12 at 20:17
prngleoprngleo
1661 silver badge4 bronze badges
1661 silver badge4 bronze badges
add a comment |
add a comment |
I had a similar problem where my additional vhosts on port 443 (SSL/HTTPS) were all being directed to the directory of the first vhost listed. Apache was essentially ignoring the servername property and matching on the ip:port only.
Turns out that I was missing the command 'NameVirtualHost *:443' to enable Named virtual hosting for port 443.
'NameVirtualHost *:443' just needs to be called once, and must be defined above your vhosts for port 443. I put my definition in the ports.config file so it looks like:
NameVirtualHost *:80
Listen 80
<IfModule mod_ssl.c>
NameVirtualHost *:443
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
NameVirtualHost *:443
Listen 443
</IfModule>
Don't forget to restart apache after any changes.
For what it's worth... in Apache 2.4.18, usingNameVirtualHost
produces this message on startup:AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/ports.conf
– Lambart
May 23 '17 at 19:49
add a comment |
I had a similar problem where my additional vhosts on port 443 (SSL/HTTPS) were all being directed to the directory of the first vhost listed. Apache was essentially ignoring the servername property and matching on the ip:port only.
Turns out that I was missing the command 'NameVirtualHost *:443' to enable Named virtual hosting for port 443.
'NameVirtualHost *:443' just needs to be called once, and must be defined above your vhosts for port 443. I put my definition in the ports.config file so it looks like:
NameVirtualHost *:80
Listen 80
<IfModule mod_ssl.c>
NameVirtualHost *:443
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
NameVirtualHost *:443
Listen 443
</IfModule>
Don't forget to restart apache after any changes.
For what it's worth... in Apache 2.4.18, usingNameVirtualHost
produces this message on startup:AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/ports.conf
– Lambart
May 23 '17 at 19:49
add a comment |
I had a similar problem where my additional vhosts on port 443 (SSL/HTTPS) were all being directed to the directory of the first vhost listed. Apache was essentially ignoring the servername property and matching on the ip:port only.
Turns out that I was missing the command 'NameVirtualHost *:443' to enable Named virtual hosting for port 443.
'NameVirtualHost *:443' just needs to be called once, and must be defined above your vhosts for port 443. I put my definition in the ports.config file so it looks like:
NameVirtualHost *:80
Listen 80
<IfModule mod_ssl.c>
NameVirtualHost *:443
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
NameVirtualHost *:443
Listen 443
</IfModule>
Don't forget to restart apache after any changes.
I had a similar problem where my additional vhosts on port 443 (SSL/HTTPS) were all being directed to the directory of the first vhost listed. Apache was essentially ignoring the servername property and matching on the ip:port only.
Turns out that I was missing the command 'NameVirtualHost *:443' to enable Named virtual hosting for port 443.
'NameVirtualHost *:443' just needs to be called once, and must be defined above your vhosts for port 443. I put my definition in the ports.config file so it looks like:
NameVirtualHost *:80
Listen 80
<IfModule mod_ssl.c>
NameVirtualHost *:443
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
NameVirtualHost *:443
Listen 443
</IfModule>
Don't forget to restart apache after any changes.
answered Oct 18 '12 at 17:17
LucasLucas
2312 silver badges2 bronze badges
2312 silver badges2 bronze badges
For what it's worth... in Apache 2.4.18, usingNameVirtualHost
produces this message on startup:AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/ports.conf
– Lambart
May 23 '17 at 19:49
add a comment |
For what it's worth... in Apache 2.4.18, usingNameVirtualHost
produces this message on startup:AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/ports.conf
– Lambart
May 23 '17 at 19:49
For what it's worth... in Apache 2.4.18, using
NameVirtualHost
produces this message on startup: AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/ports.conf
– Lambart
May 23 '17 at 19:49
For what it's worth... in Apache 2.4.18, using
NameVirtualHost
produces this message on startup: AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/ports.conf
– Lambart
May 23 '17 at 19:49
add a comment |
My 2 cents: as I have to stick with an IP (I don't want the site to be served on all networks installed), it happened that after the local private IP of the server changed, I forgot to change it here:
NameVirtualHost 192.168.100.20:80
<VirtualHost 192.168.100.20:80>
Of course it's not an Apache problem to let you know that IP does not exist locally.
add a comment |
My 2 cents: as I have to stick with an IP (I don't want the site to be served on all networks installed), it happened that after the local private IP of the server changed, I forgot to change it here:
NameVirtualHost 192.168.100.20:80
<VirtualHost 192.168.100.20:80>
Of course it's not an Apache problem to let you know that IP does not exist locally.
add a comment |
My 2 cents: as I have to stick with an IP (I don't want the site to be served on all networks installed), it happened that after the local private IP of the server changed, I forgot to change it here:
NameVirtualHost 192.168.100.20:80
<VirtualHost 192.168.100.20:80>
Of course it's not an Apache problem to let you know that IP does not exist locally.
My 2 cents: as I have to stick with an IP (I don't want the site to be served on all networks installed), it happened that after the local private IP of the server changed, I forgot to change it here:
NameVirtualHost 192.168.100.20:80
<VirtualHost 192.168.100.20:80>
Of course it's not an Apache problem to let you know that IP does not exist locally.
answered Feb 29 '16 at 13:15
maraboshimaraboshi
413 bronze badges
413 bronze badges
add a comment |
add a comment |
Tom, please look here
http://httpd.apache.org/docs/2.0/en/mod/core.html#namevirtualhost
Note
Note, that the "main server" and any
default servers will never be served for a request to a NameVirtualHost IP
address (unless for some reason you
specify NameVirtualHost but then don't
define any VirtualHosts for that
address).
So it should be okay if you change the default to the ip-adress of your server.
I tried that, but it didn't change anything. I'd also like to avoid tying myself to a particular IP, so I'm going to change it back. Also, I should point out that the default vhost is the one that works.
– Tom Wright
Jul 8 '11 at 13:52
add a comment |
Tom, please look here
http://httpd.apache.org/docs/2.0/en/mod/core.html#namevirtualhost
Note
Note, that the "main server" and any
default servers will never be served for a request to a NameVirtualHost IP
address (unless for some reason you
specify NameVirtualHost but then don't
define any VirtualHosts for that
address).
So it should be okay if you change the default to the ip-adress of your server.
I tried that, but it didn't change anything. I'd also like to avoid tying myself to a particular IP, so I'm going to change it back. Also, I should point out that the default vhost is the one that works.
– Tom Wright
Jul 8 '11 at 13:52
add a comment |
Tom, please look here
http://httpd.apache.org/docs/2.0/en/mod/core.html#namevirtualhost
Note
Note, that the "main server" and any
default servers will never be served for a request to a NameVirtualHost IP
address (unless for some reason you
specify NameVirtualHost but then don't
define any VirtualHosts for that
address).
So it should be okay if you change the default to the ip-adress of your server.
Tom, please look here
http://httpd.apache.org/docs/2.0/en/mod/core.html#namevirtualhost
Note
Note, that the "main server" and any
default servers will never be served for a request to a NameVirtualHost IP
address (unless for some reason you
specify NameVirtualHost but then don't
define any VirtualHosts for that
address).
So it should be okay if you change the default to the ip-adress of your server.
answered Jul 8 '11 at 13:41
Marcel KronenbergMarcel Kronenberg
211 bronze badge
211 bronze badge
I tried that, but it didn't change anything. I'd also like to avoid tying myself to a particular IP, so I'm going to change it back. Also, I should point out that the default vhost is the one that works.
– Tom Wright
Jul 8 '11 at 13:52
add a comment |
I tried that, but it didn't change anything. I'd also like to avoid tying myself to a particular IP, so I'm going to change it back. Also, I should point out that the default vhost is the one that works.
– Tom Wright
Jul 8 '11 at 13:52
I tried that, but it didn't change anything. I'd also like to avoid tying myself to a particular IP, so I'm going to change it back. Also, I should point out that the default vhost is the one that works.
– Tom Wright
Jul 8 '11 at 13:52
I tried that, but it didn't change anything. I'd also like to avoid tying myself to a particular IP, so I'm going to change it back. Also, I should point out that the default vhost is the one that works.
– Tom Wright
Jul 8 '11 at 13:52
add a comment |
I find answer from here: http://alexking.org/blog/2007/11/01/apache-2-only-serves-first-virtual-host
Put 2 servername in same 1 VirtualHost tag as below:
<VirtualHost *:80>
ServerName beta-site-1.com
DocumentRoot "/Library/WebServer/beta-site-1"
ServerName beta-site-2.com
DocumentRoot "/Library/WebServer/beta-site-2"
</VirtualHost>
I ended up having issues with the second site because I had two VirtualHost tag blocks.
add a comment |
I find answer from here: http://alexking.org/blog/2007/11/01/apache-2-only-serves-first-virtual-host
Put 2 servername in same 1 VirtualHost tag as below:
<VirtualHost *:80>
ServerName beta-site-1.com
DocumentRoot "/Library/WebServer/beta-site-1"
ServerName beta-site-2.com
DocumentRoot "/Library/WebServer/beta-site-2"
</VirtualHost>
I ended up having issues with the second site because I had two VirtualHost tag blocks.
add a comment |
I find answer from here: http://alexking.org/blog/2007/11/01/apache-2-only-serves-first-virtual-host
Put 2 servername in same 1 VirtualHost tag as below:
<VirtualHost *:80>
ServerName beta-site-1.com
DocumentRoot "/Library/WebServer/beta-site-1"
ServerName beta-site-2.com
DocumentRoot "/Library/WebServer/beta-site-2"
</VirtualHost>
I ended up having issues with the second site because I had two VirtualHost tag blocks.
I find answer from here: http://alexking.org/blog/2007/11/01/apache-2-only-serves-first-virtual-host
Put 2 servername in same 1 VirtualHost tag as below:
<VirtualHost *:80>
ServerName beta-site-1.com
DocumentRoot "/Library/WebServer/beta-site-1"
ServerName beta-site-2.com
DocumentRoot "/Library/WebServer/beta-site-2"
</VirtualHost>
I ended up having issues with the second site because I had two VirtualHost tag blocks.
edited Sep 18 '16 at 18:35
Community♦
1
1
answered Jul 7 '16 at 12:15
Tu UyenTu Uyen
111 bronze badge
111 bronze badge
add a comment |
add a comment |
I had this problem migrating sites to a new Ubuntu 16 server. After a bit of head-scratching, I realised the SSL Module was not enabled by default, so anything inside the <IfModule mod_ssl.c>
blocks is of course silently ignored.
Years ago I wrapped all my SSL vhosts in this conditional, and this time I had just copied the config files across to the new server.
I fixed it by enabling the module:
sudo a2enmod ssl
add a comment |
I had this problem migrating sites to a new Ubuntu 16 server. After a bit of head-scratching, I realised the SSL Module was not enabled by default, so anything inside the <IfModule mod_ssl.c>
blocks is of course silently ignored.
Years ago I wrapped all my SSL vhosts in this conditional, and this time I had just copied the config files across to the new server.
I fixed it by enabling the module:
sudo a2enmod ssl
add a comment |
I had this problem migrating sites to a new Ubuntu 16 server. After a bit of head-scratching, I realised the SSL Module was not enabled by default, so anything inside the <IfModule mod_ssl.c>
blocks is of course silently ignored.
Years ago I wrapped all my SSL vhosts in this conditional, and this time I had just copied the config files across to the new server.
I fixed it by enabling the module:
sudo a2enmod ssl
I had this problem migrating sites to a new Ubuntu 16 server. After a bit of head-scratching, I realised the SSL Module was not enabled by default, so anything inside the <IfModule mod_ssl.c>
blocks is of course silently ignored.
Years ago I wrapped all my SSL vhosts in this conditional, and this time I had just copied the config files across to the new server.
I fixed it by enabling the module:
sudo a2enmod ssl
answered Jul 11 '17 at 4:38
scipilotscipilot
1616 bronze badges
1616 bronze badges
add a comment |
add a comment |
I discovered the source of this problem was an /etc/hosts entry on my server with the URL in it pointing to the server's external IP.
At one point I must have been setting it up before DNS was ready so I entered a /etc/hosts entry on my server pointing to its own external IP:
1.2.3.4 vhost.example.com
Then i set up a ServerAlias to an existing site for "vhost.example.com"
But nothing I could do would stop Apache serving up the default-ssl.conf site for SSL requests to vhost.example.com. Port 80 HTTP worked OK, but the SSL always showed the default site instead. In the end this SO thread led me to try "apachectl -S" which shows sites and finally I was able to figure it out.
So if you're getting the default SSL site instead of the site you're expecting, make sure you didn't add your server's external IP address in a /etc/hosts entry! A pretty weird thing to have done in hindsight, but hopefully this helps someone else!
add a comment |
I discovered the source of this problem was an /etc/hosts entry on my server with the URL in it pointing to the server's external IP.
At one point I must have been setting it up before DNS was ready so I entered a /etc/hosts entry on my server pointing to its own external IP:
1.2.3.4 vhost.example.com
Then i set up a ServerAlias to an existing site for "vhost.example.com"
But nothing I could do would stop Apache serving up the default-ssl.conf site for SSL requests to vhost.example.com. Port 80 HTTP worked OK, but the SSL always showed the default site instead. In the end this SO thread led me to try "apachectl -S" which shows sites and finally I was able to figure it out.
So if you're getting the default SSL site instead of the site you're expecting, make sure you didn't add your server's external IP address in a /etc/hosts entry! A pretty weird thing to have done in hindsight, but hopefully this helps someone else!
add a comment |
I discovered the source of this problem was an /etc/hosts entry on my server with the URL in it pointing to the server's external IP.
At one point I must have been setting it up before DNS was ready so I entered a /etc/hosts entry on my server pointing to its own external IP:
1.2.3.4 vhost.example.com
Then i set up a ServerAlias to an existing site for "vhost.example.com"
But nothing I could do would stop Apache serving up the default-ssl.conf site for SSL requests to vhost.example.com. Port 80 HTTP worked OK, but the SSL always showed the default site instead. In the end this SO thread led me to try "apachectl -S" which shows sites and finally I was able to figure it out.
So if you're getting the default SSL site instead of the site you're expecting, make sure you didn't add your server's external IP address in a /etc/hosts entry! A pretty weird thing to have done in hindsight, but hopefully this helps someone else!
I discovered the source of this problem was an /etc/hosts entry on my server with the URL in it pointing to the server's external IP.
At one point I must have been setting it up before DNS was ready so I entered a /etc/hosts entry on my server pointing to its own external IP:
1.2.3.4 vhost.example.com
Then i set up a ServerAlias to an existing site for "vhost.example.com"
But nothing I could do would stop Apache serving up the default-ssl.conf site for SSL requests to vhost.example.com. Port 80 HTTP worked OK, but the SSL always showed the default site instead. In the end this SO thread led me to try "apachectl -S" which shows sites and finally I was able to figure it out.
So if you're getting the default SSL site instead of the site you're expecting, make sure you didn't add your server's external IP address in a /etc/hosts entry! A pretty weird thing to have done in hindsight, but hopefully this helps someone else!
answered Jun 6 at 17:37
Professor FalkenProfessor Falken
1563 bronze badges
1563 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f288284%2fwhy-might-apache-ignore-a-virtual-host-with-a-servername-matching-the-requested%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Not sure this is the cause, but you ought to remove the slashes from the ends of your
ServerName
andServerAlias
lines. Also, make sure you've restarted apache.– EEAA
Jul 8 '11 at 12:53
I'm almost positive that's the cause. It means the hostname in the request will never match the ServerName for that virtual host.
– larsks
Jul 8 '11 at 12:57
1
@ErikA, @larsks - You guys got my hopes up! I removed the trailing slashes and restarted apache, but it didn't change anything.
– Tom Wright
Jul 8 '11 at 13:12
1
Do you have
NameVirtualHost *:80
somewhere in your configuration?– larsks
Jul 8 '11 at 13:15
1
I am not sure if the sites mentioned above are production or development, but actually going to those URLs does give two different pages for me (correct pages by the looks of it). If the vhosts above are on a development server, ignore this comment. Otherwise, you might have fixed your problem somewhere along the way and still have a cached copy sitting around.
– cyberx86
Jul 8 '11 at 17:30