Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Apache virtual hosts
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
marxin
n00b
n00b


Joined: 28 Oct 2005
Posts: 28

PostPosted: Mon Aug 04, 2008 6:13 pm    Post subject: Apache virtual hosts Reply with quote

I'm trying to run 2 name-based virtual hosts on my Gentoo box, but I'm not succesfull.

/etc/conf.d/apache2
Code:

APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D LANGUAGE -D PHP5 -D SSL_DEFAULT_VHOST"


00_marxin.eu_vhost.conf
Code:

<IfDefine DEFAULT_VHOST>
Listen 80
NameVirtualHost *:80
<VirtualHost marxin.eu>
        ServerName marxin.eu
        ServerAlias www.marxin.eu
        Include /etc/apache2/vhosts.d/marxin.eu_vhost.include

        <IfModule mpm_peruser_module>
                ServerEnvironment apache apache
        </IfModule>
</VirtualHost>
</IfDefine>



00_gameground.cz_vhost.conf
Code:

<IfDefine DEFAULT_VHOST>
Listen 80
NameVirtualHost *

<VirtualHost gameground.cz>
        ServerName gameground.cz
        ServerAlias www.gameground.cz
        Include /etc/apache2/vhosts.d/gameground.cz_vhost.include

        <IfModule mpm_peruser_module>
                ServerEnvironment apache apache
        </IfModule>
</VirtualHost>
</IfDefine>


/etc/hosts
Code:

127.0.0.1       localhost
77.48.17.118    marxin.eu
77.48.17.118    gameground.cz
::1             localhost


ifconfig
Code:

eth0      Link encap:Ethernet  HWaddr 00:16:17:81:71:87
          inet addr:77.48.17.118  Bcast:77.48.17.119  Mask:255.255.255.252
          inet6 addr: fe80::216:17ff:fe81:7187/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:17127 errors:0 dropped:0 overruns:0 frame:0
          TX packets:18708 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1769390 (1.6 Mb)  TX bytes:2786294 (2.6 Mb)
          Interrupt:23 Base address:0xc800


/etc/init.d/apache2 start
Code:

 * Caching service dependencies ...                                                                                                                    [ ok ]
 * Starting apache2 ...
apache2: apr_sockaddr_info_get() failed for marxin_server
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[Mon Aug 04 20:12:50 2008] [warn] VirtualHost marxin.eu:0 overlaps with VirtualHost gameground.cz:0, the first has precedence, perhaps you need a NameVirtualHost directive
[Mon Aug 04 20:12:50 2008] [warn] NameVirtualHost *:0 has no VirtualHosts
[Mon Aug 04 20:12:50 2008] [warn] NameVirtualHost *:80 has no VirtualHosts
(98)Address already in use: make_sock: could not bind to address [::]:80                                                                               


Thanks for your advices, marxin
Back to top
View user's profile Send private message
FlorianSchmidt
Tux's lil' helper
Tux's lil' helper


Joined: 20 May 2008
Posts: 77
Location: Germany

PostPosted: Tue Aug 05, 2008 10:46 am    Post subject: Reply with quote

In 00_marxin.eu_vhost.conf change
Code:
NameVirtualHost *:80

into
Code:
NameVirtualHost *

(This is more or less just a suggestion)
and
Code:
<VirtualHost marxin.eu>

into:
Code:
<VirtualHost *>

because of http://httpd.apache.org/docs/2.2/mod/core.html#namevirtualhost

in 00_gameground.cz_vhost.conf delete
Code:

Listen 80
NameVirtualHost *

You must not have more than one "Listen 80" in your whole apache configuration and you only need to define "NameVirtualHost" once, at least for what it looks like you are planning to do.

And change
Code:
<VirtualHost gameground.cz>

into
Code:
<VirtualHost *>


So much for the apache stuff, lets have a look if that helps.

In general, if you really want to divide the configuration into seperated files, you should place the NameVirtualHost and Listen directives in your "main" configuration file, because they have a more general meaning. Sometimes there is also a listen.conf for the Listen directive exclusive, I think debian is doing it that way... Hmm, at this point I must admit that I have no idea how gentoo is doing it, anyway the suggestions made above will work.
_________________
-bash: :wq: command not found
Back to top
View user's profile Send private message
kashani
Advocate
Advocate


Joined: 02 Sep 2002
Posts: 2032
Location: San Francisco

PostPosted: Tue Aug 05, 2008 5:26 pm    Post subject: Reply with quote

You've got too many Listen statements. Here's how I set mine up. First off I generally leave the default installed Gentoo default_vhost and defualt.vhost.include files alone. I don't care about traffic that hits my server without specifying a domain name and rather it just hits a blank vhost.

/etc/apache2/vhosts.d/00_default_vhost.conf
Code:

<IfDefine DEFAULT_VHOST>
Listen 80
NameVirtualHost *:80

<VirtualHost *:80>
        ServerName localhost
        Include /etc/apache2/vhosts.d/default_vhost.include

        <IfModule mpm_peruser_module>
                ServerEnvironment apache apache
        </IfModule>
</VirtualHost>
</IfDefine>


Now I start defining my vhosts. No Listen statements, not NameVirtualHost, etc because you've already entered all that in the default_vhost.conf.
/etc/apache2/vhosts.d/badapple.net.conf
Code:

<VirtualHost *:80>
ServerName badapple.net
ServerAlias www.badapple.net
ServerAdmin webmaster@badapple.net
DocumentRoot /var/www/badapple.net/htdocs

CustomLog /var/log/apache2/badapple.net.access.log combined
ErrorLog /var/log/apache2/badapple.net.error.log

# PHP tweaks
php_value post_max_size 104857600
php_value upload_max_filesize 104857600

<Directory "/var/www/badapple.net/htdocs">
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
</Directory>

RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]

</VirtualHost>


You can continue to define the DEFAULT_VHOST stuff in each vhost you create, but generally I assume I want all my vhosts all the time.

kashani
_________________
Will personally fix your server in exchange for motorcycle related shop tools in good shape.
Back to top
View user's profile Send private message
leonardosam
n00b
n00b


Joined: 28 Nov 2007
Posts: 10
Location: Campinas, Brazil

PostPosted: Thu Dec 11, 2008 11:29 pm    Post subject: Same problem here Reply with quote

Hey guys,

I'm running into the same stupid problem here and can't find where the problem is. I have tried many suggestions and none seemed to work. I have a default host in www.x.com and the one that I want to work under /home/user/public_html is www.y.com , however, whenever I try to open www.y.com , I end up at www.x.com

It is driving me crazy.

Here's my configuration:

/etc/conf.d/apache2

Code:
APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D LANGUAGE -D SSL -D SSL_DEFAULT_VHOST -D PHP5 -D MAILMAN -D USERDIR -D STATUS"


/etc/apache2/httpd.conf
Code:

Include /etc/apache2/vhosts.d/*.conf


/etc/apache2/vhosts.d/00_default_vhost.conf

Code:
<IfDefine DEFAULT_VHOST>
Listen 80
NameVirtualHost *:80
  <VirtualHost *:80>
    ServerName  x.com
    ServerAlias www.x.com
    Include     /etc/apache2/vhosts.d/default_vhost.include

    <IfModule mpm_peruser_module>
      ServerEnvironment apache apache
    </IfModule>
  </VirtualHost>
</IfDefine>


/etc/apache2/vhosts.d/01_y_com.conf

Code:
<IfDefine DEFAULT_VHOST>
  <VirtualHost *:80>
    ServerName y.com
    ServerAlias www.y.com
    DocumentRoot /home/user/public_html
  </VirtualHost>
</IfDefine>


Plus, I have modules alias and virtualhost_alias loaded.

Everything seems to be okay, right? What the heck is going on in here anyway?

I would appreciate any support. Thank you.
Back to top
View user's profile Send private message
cach0rr0
Bodhisattva
Bodhisattva


Joined: 13 Nov 2008
Posts: 4123
Location: Houston, Republic of Texas

PostPosted: Sun Dec 14, 2008 10:52 pm    Post subject: Reply with quote

@leonardosam

I don't see anywhere that your y.com vhost is actually configured to use that .conf file

I only see default_vhost.include

Here is how I have mine set up, which works

00_default_vhost.conf snippet:

Code:


<IfDefine DEFAULT_VHOST>
Listen 80

# Use name-based virtual hosting.
NameVirtualHost *:80

<VirtualHost *:80>
   ServerName mydomain.com
   Include /etc/apache2/vhosts.d/default_vhost.include

   <IfModule mpm_peruser_module>
      ServerEnvironment apache apache
   </IfModule>
</VirtualHost>
<VirtualHost *:80>
        ServerName eu.mydomain.com
        Include /etc/apache2/vhosts.d/eu_vhost.include
   php_admin_value session.save_path "/var/www/eu/tmp"
   php_admin_value file_uploads off
        <IfModule mpm_peruser_module>
                ServerEnvironment apache apache
        </IfModule>
</VirtualHost>



Notice the Include statement in the second block? and of course, snippet of eu_vhost.include

Code:

DocumentRoot "/var/www/eu/htdocs"

<Directory "/var/www/eu/htdocs">
   Options Indexes FollowSymLinks
   AllowOverride All
   Order allow,deny
   Allow from all
</Directory>


note that when you include all *.conf in your main httpd.conf is going to be out of whack with your file named as it is. You need apache to include that config in a very specific place, so you use the Include directive as I have above.

hope that helps
Back to top
View user's profile Send private message
cach0rr0
Bodhisattva
Bodhisattva


Joined: 13 Nov 2008
Posts: 4123
Location: Houston, Republic of Texas

PostPosted: Sun Dec 14, 2008 11:02 pm    Post subject: Reply with quote

sorry for the double post, im watching the game and distracted :)

So, first and foremost, let's rename that file

Code:

mv /etc/apache2/vhosts.d/01_y_com.conf /etc/apache2/vhosts.d/01_y_com.include


then change your 00_default_vhost.conf to be like so:

Code:

<IfDefine DEFAULT_VHOST>
Listen 80
NameVirtualHost *:80
  <VirtualHost *:80>
    ServerName  x.com
    ServerAlias www.x.com
    Include     /etc/apache2/vhosts.d/default_vhost.include
    <IfModule mpm_peruser_module>
      ServerEnvironment apache apache
    </IfModule>
  </VirtualHost>
  <VirtualHost *:80>
    ServerName y.com
    ServerAlias www.y.com
    Include      /etc/apache2/vhosts.d/01_y_com.include
    <IfModule mpm_peruser_module>
      ServerEnvironment apache apache
    </IfModule>
  </VirtualHost>
</IfDefine>


Then change 01_y_com.include like so:

Code:

DocumentRoot "/home/user/public_html"

<Directory "/home/user/public_html">
   Options Indexes FollowSymLinks
   AllowOverride All
   Order allow,deny
   Allow from all
</Directory>


restart apache and see how you go
Back to top
View user's profile Send private message
leonardosam
n00b
n00b


Joined: 28 Nov 2007
Posts: 10
Location: Campinas, Brazil

PostPosted: Sun Dec 14, 2008 11:24 pm    Post subject: Corrected Reply with quote

Everything was fine regarding the configuration. I was trying to setup the vhost without any further configuration first. The problem is that Apache does not accept to have virtual hosts under a public_html (~username) directory.

It is now running sound and smoothly.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum