Реклама: |
Virtual host. |
I am trying to set up a FreeBSD server as web server for virtual hosting.
That is, provide www services for both http://www.mydomain.com and
http://www.othersdomain.com. Creating Virtual WWW Servers With BSD by Ralph Huntington These are simple techniques that are known to work with FreeBSD 2.x and 3.x and BSD/OS 2.x, 3.x 4.x. I expect they are just as workable with just about any flavor of BSD. These instructions assume you are using a recent distribution of the Apache http daemon and that appropriate directories are in place on the server (or on a mounted drive or partition) for the virtual host's http documents and logs. Also assumed is that domain name services are in place for the virtual domain and that an IP address has been assigned. [Note: These instructions differ slightly from those suggested by BSDI in the release notes for BSD/OS 2.1. My (humble) opinion is that these techniques are slightly less mystical and slightly easier to implement.] There are three things you need to do: 1. Bind the IP Address to the Ethernet Card Place a line in /etc/rc.local that looks like this: ifconfig $nic inet $ipaddress netmask $mask alias and another one like this: route add -host $ipaddress 127.0.0.1 where $nic is the Ethernet device and $ipaddress is the IP address of the virtual domain or host. That will take care of it the next time you boot. To make it all take effect immediately, issue the same commands from the prompt. You may get a message saying 'File Exists'. Ignore that. Try to ping the address and/or the name. If pinging fails, the address is not being bound to the Ethernet device for some reason. You will need to solve that problem before proceeding. 2. tell the http daemon about the virtual host You will need to edit the httpd configuration file httpd.conf which is usually found in /usr/local/www/server/conf/ or /usr/local/www/config/ or /usr/local/apache/conf/ on FreeBSD machines and in /var/www/conf/ on BSDI boxes. Go to the BindAddress line and make it say BindAddress * Move to the end of the file and create a VirtualHost entry for each host, including the 'real' host. Two are shown here, one for the 'real' host and one for a virtual host. Any httpd.conf or srm.conf directive may go into a VirtualHost entry. Directives entered here override prior directives. <VirtualHost a.b.c.d> # 'real' host IP address ServerAdmin webmaster@primary-domain.net# @your-domain ServerRoot /var/www/ # or wherever it is... DocumentRoot /var/www/docs/ # likewise... ServerName www.primary-domain.net ErrorLog /var/www/logs/error_log # wherever you keep them TransferLog /var/www/logs/access_log # daemon will start logs Alias /icons/ /var/www/icons/ ScriptAlias /cgi-bin/ /var/www/scripts/ # or whatever... AddType text/x-server-parsed-html .html AddType application/x-httpd-cgi .cgi # just examples. DefaultType text/plain </VirtualHost> # don't forget this line. <VirtualHost a.b.c.e> # virtual host IP address ServerAdmin webmaster@virtual-domain.com# @virtual-domain ServerRoot /var/www/ # keep this the same DocumentRoot /some/path/docs/ ServerName www.virtual-domain.com ErrorLog /some/path/logs/error_log TransferLog /some/path/logs/access_log Alias /icons/ /var/www/icons/ # use standards. Alias /images/ /some/path/images/ # their own stuff. ScriptAlias /cgi-bin/ /var/www/scripts/ # scripts must be approved. DefaultType text/plain </VirtualHost> 3. SIGHUP and Test # /apache/bin/apachectl restart (I symlink /usr/local/apache/ to /apache/) or simply # kill -HUP `cat httpd.pid` At this point, you should be up and running and able to serve docs. Make sure the http daemon is still running. If there is an error in httpd.conf that cannot be resolved, such as a non-existant directory, the daemon will die. If the daemon does die, issue the command httpd right from the command line (as root, of course) and it will give you the line number in httpd.conf that has the problem. Once you know the daemon is running, try to bring up the virtual host's index.html page in your browser. If you cannot, then you have a configuration error of some kind. Try to bring up the 'real' hosts home page, also. If you cannot, make sure all directories referenced in httpd.conf actually exist and are world readable. If there are things that cannot be resolved, the daemon will not start at all. Every time you try to start the daemon, check the logs. If you can, have a window running % tail -f /var/log/messages Check all the logs for clues. Usually it's a missing file or directory or a syntax error in a configuration file. Try testing the daemon from the command line: # /apache/bin/apachectl configtest and see what message (if any) you get back. If you receive no error message, the daemon is probably running. Verify this with: % ps ax | grep httpd You should see a parent and several child daemons running. |