Vhost Config issues

Ryan Schmidt ryandesign at macports.org
Fri Sep 3 02:54:45 PDT 2010


On Sep 3, 2010, at 04:48, Jasper Frumau wrote:

> OK I have activated virtualhosts by uncommenting this line in /opt/local/apache2/httpd.conf:
> 
> $ cat httpd.conf | grep httpd-v
> Include conf/extra/httpd-vhosts.conf
> 
> in httpd-vhosts.conf I have:
> 
> $ sudo cat httpd-vhosts.conf
> #
> # Virtual Hosts
> #
> # If you want to maintain multiple domains/hostnames on your
> # machine you can setup VirtualHost containers for them. Most configurations
> # use only name-based virtual hosts so the server doesn't need to worry about
> # IP addresses. This is indicated by the asterisks in the directives below.
> #
> # Please see the documentation at 
> # <URL:http://httpd.apache.org/docs/2.2/vhosts/>
> # for further details before you try to setup virtual hosts.
> #
> # You may use the command line option '-S' to verify your virtual host
> # configuration.
> 
> #
> # Use name-based virtual hosting.
> #
> NameVirtualHost *:80
> 
> #
> # VirtualHost example:
> # Almost any Apache directive may go into a VirtualHost container.
> # The first VirtualHost section is used for all requests that do not
> # match a ServerName or ServerAlias in any <VirtualHost> block.
> #
> <VirtualHost *:80>
>     ServerAdmin webmaster at dummy-host.example.com
>     DocumentRoot "/opt/local/www/"
> #    ServerName dummy-host.example.com
> #    ServerAlias www.dummy-host.example.com
> #    ErrorLog "logs/dummy-host.example.com-error_log"
> #    CustomLog "logs/dummy-host.example.com-access_log" common
> </VirtualHost>
> #
> # Pull in all my virtual hosts, which are filename format of hostname.example.com.conf
> # ie: ends in .conf
> Include conf/extra/vhosts/*.conf
> # -- END --
> #
> #<VirtualHost *:80>
> #    ServerAdmin webmaster at dummy-host2.example.com
> #    DocumentRoot "/opt/local/apache2/htdocs/apt1"
> #    ServerName apt1
> #</VirtualHost>
> 
> 
> So all new VirtualHost configurations in conf/extra/vhosts/ should be loaded, right?

Yes, you could do it like that if you want.

Note that if your virtual hosts are located in subdirectories of /opt/local/www (as you showed us for your wordpress virtual host in the last email), then your default virtual host should definitely not have the document root /opt/local/www, otherwise anybody could access e.g. your wordpress via http://somehost/wordpress (where "somehost" is a hostname or IP address that points to your machine but is not mentioned specifically in a VirtualHost block) and could conceivably read files they should not have access to. Instead, set your default virtual host's document root to another subdirectory of /opt/local/www, for example /opt/local/www/default.


> On Fri, Sep 3, 2010 at 1:16 PM, Jasper Frumau wrote:
> 
>> So I d not need these lines:
>> 
>> 
>> ##
>> > 127.0.0.1    localhost
>> > 127.0.0.1       jaspersmbp
>> > 127.0.0.1       dev-wordpress.com
>> > 255.255.255.255    broadcasthost
>> > ::1             localhost
>> > fe80::1%lo0    localhost
>> 
>>  in my HOSTS file as long as I have vhost files to takae care of it? I see it still only understand a tiny bit...

You do still need to define entries in /etc/hosts for every fake hostname you want to use. You can take a shortcut and put them all on one line if you like:

127.0.0.1 localhost jaspersmbp dev-wordpress.com





More information about the macports-users mailing list