Logo Page Web Française
Accueil Association BSD Linux Dev Reseau Infologisme Mac OSX
tl tr
Subject IP Address Date 2009-11-12
Title DNS Resolving Hostname and hosts File - Apache name based hosting Section Dev Reseau
Article

For an BIND installing see the article:

BIND Système Nom Domaine - FreeBSD

BIND Système Nom Domaine - Linux Fedora


Configure Apache to serve with the Domain Names, it is initially necessary to make some oprations on the server.

It is obvious that site-name.com represent for example: c-extra.com


Operating system:

Fedora 12 FC12 and earlier Versions or another Linux distribution.
FreeBSD FreeBSD - Install and Configure version 7.2-RELEASE or another Unix.



Necessary softwares and servers:


Composants ou Packages FreeBSD Apache

Composants ou Packages Fedora Apache

See the article on the installing of Webmin - System and server administration


DNS resolve, Hostname and host File

A little complex concept when one installs a server for hosted web site on the names, DNS and IP Address it is much of abstract.

When one installs Fedora Core or another Linux distribution or a Unix, comes the moment from interrogation in front of three small magic fields and a name of machine or hostname. Everyone is said, the DHCP and one will see later, more disastrous error one little!

The name of the station, name of machine or hostname, must be in a domain. Domain Name System or DNS, the first domain is it not com whose site-name makes party and the name of the server is product. What gives us:

product.site-name.com

Here is for the name of the station, and maintaining the servers DNS, the first to serve the domain it is the server, thus one puts address IP of the server 192.168.1.1 by principle one always puts the server into 1 in class IP concerned, but when one has several servers in the same class Networking 1 then 2 then 3.

The two others are the primary and secondary DNS of your Internet Provider.

What gives us:

Server address: 192.168.1.1
Primary DNS: 80.10.246.2
Secondary DNS: 80.10.246.129

Webmin enables us to visualize all that!

With Webmin, the section Networking then Network Configuration then Hostname and DNS Client must be configured like below.

 DNS Client Options
Hostname Resolution order
  Update hostname in host addresses if changed?
DNS servers


Search domains None Listed ..

The resolv.conf file which is in the folder or repertory /etc/resolv.conf, also shows it.

product site-name.com
nameserver 192.168.1.1
nameserver 80.10.246.2
nameserver 80.10.246.129


Hostname or name of machine

Never not to remove the first line it is the Loopback address, 127.0.0.1

Same address IP that of the server, all must serve the domains enumerated below. It is this parameter which should be adopted to serve on the domain names with Bind and Apache.

Once again Webmin enables us to visualize all that!

With Webmin, the section Networking then Network Configuration then Host Addresses must be configured like below.

Select all. | Invert selection. | Add a new host address.
IP Address Hostnames
127.0.0.1 product.site-name.com , product , localhost.localdomain , localhost
::1 product.site-name.com , product , localhost.localdomain , localhost
192.168.1.1 site-name.com , www.site-name.com , ftp.site-name.com , mail.site-name.com
192.168.1.1 site-name.net , www.site-name.net , ftp.site-name.net , mail.site-name.net
192.168.1.1 site-name2.com , www.site-name2.com , ftp.site-name2.com , mail.site-name2.com
192.168.1.1 site-name2.net , www.site-name2.net , ftp.site-name2.net , mail.site-name2.net
192.168.1.1 site-name3.com , www.site-name3.com , ftp.site-name3.com , mail.site-name3.com
192.168.1.1 site-name3.net , www.site-name3.net , ftp.site-name3.net , mail.site-name3.net
Select all. | Invert selection. | Add a new host address.

The hosts file that is in the folder or directory /etc/hosts it also shows.


Version Linux Fedora


# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1       product.site-name.com product localhost.localdomain localhost
::1             product.site-name.com product localhost.localdomain localhost
192.168.1.1     site-name.com www.site-name.com ftp.site-name.com mail.site-name.com
192.168.1.1     site-name.fr www.site-name.fr ftp.site-name.fr mail.site-name.fr
192.168.1.1     site-name.net www.site-name.net ftp.site-name.net mail.site-name.net
192.168.1.1     site-name2.com www.site-name2.com ftp.site-name2.com mail.site-name2.com
192.168.1.1     site-name2.net www.site-name2.net ftp.site-name2.net mail.site-name2.net
192.168.1.1     site-name3.com www.site-name3.com ftp.site-name3.com mail.site-name3.com
192.168.1.1     site-name3.net www.site-name3.net ftp.site-name3.net mail.site-name3.net



Version FreeBSD


# Generated by Eric Douzet - Mon Jun 30 12:00:00 2008
#
# FreeBSD /etc/hosts
#
#
::1             product.c-extra.com localhost.c-extra.com localhost
127.0.0.1       product.c-extra.com localhost.c-extra.com localhost
192.168.1.1     site-name.com www.site-name.com ftp.site-name.com mail.site-name.com
192.168.1.1     site-name.fr www.site-name.fr ftp.site-name.fr mail.site-name.fr
192.168.1.1     site-name.net www.site-name.net ftp.site-name.net mail.site-name.net
192.168.1.1     site-name2.com www.site-name2.com ftp.site-name2.com mail.site-name2.com
192.168.1.1     site-name2.net www.site-name2.net ftp.site-name2.net mail.site-name2.net
192.168.1.1     site-name3.com www.site-name3.com ftp.site-name3.com mail.site-name3.com
192.168.1.1     site-name3.net www.site-name3.net ftp.site-name3.net mail.site-name3.net
#
#



The file /etc/hosts is to be edited by the software emacs and on a well-adapted to its own Web sites.


Resolving Domain Name


Apache parameters to serve on the domain names

Create an « site-name.com » user with Webmin, to go on the System icon then last icon Users and Groups. Respect the breakage of the word « site-name.com », because the Unix makes the difference between the capital letters and the tiny ones.


User Details
Username
User ID Automatic Calculated
Real name
Home directory Automatic
Directory
 
Shell  
Password
No password required
No login allowed
Normal password
Pre-encrypted password
   Login temporarily disabled
Password Options
Options not used for these parameters
Group Membership
Primary group
New group with same name as user
New group
Existing group
Secondary groups
All groups In groups

Upon Creation...
Create home directory? Yes No
Copy template files to home directory? Yes No
Create user in other modules? Yes No


After having made a user and group site-name.com having the User ID 600 for Fedora Linux or for FreeBSD having the User ID 1000 in the directory:

/home/site-name.com/

Create the following folders or directories:

/home  
  /site-name.com  
  /cgi-bin  
  /html  
  /art
  /Connect
  /doc
  /en
  /fr
  /img
  /lib
  /txt
  /logs  
  /stats  

Add to the httpd.conf File located in the folder or directory /etc/httpd/conf/httpd.conf for Fedora Linux or for FreeBSD
/usr/local/etc/apache22/httpd.conf the following lines:


NameVirtualHost 192.168.1.1

<VirtualHost www.site-name.com>
SuexecUserGroup "#600" "#600" * FreeBSD "#1000" "#1000"
ServerName site-name.com
ServerAlias www.site-name.com
DocumentRoot /home/site-name.com/html
ErrorLog /home/site-name.com/logs/error_log
CustomLog /home/site-name.com/logs/access_log "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
ScriptAlias /cgi-bin/ /home/site-name.com/cgi-bin/
<Directory /home/site-name.com/html>
Options Indexes IncludesNOEXEC FollowSymLinks
allow from all
# AllowOverride All * For Fedora Linux
</Directory>
<Directory /home/site-name.com/cgi-bin>
allow from all
</Directory>
AddDefaultCharset iso-8859-1
DefaultLanguage en
LanguagePriority en * Or an other localization
</VirtualHost>



Remark :

Protect each directory /art /Connect /doc /en /fr /img /lib /txt by inserting the File index.php ou index.html in each directory which sends back to the root directory of the Web site /home/site-name.com/html of this type:


index.php or index.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<!-- Meta Tags -->
<title>C-extra.com - System Unix Informations !</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Refresh" content="0; URL=../index.php"> * or ../index.html
<meta name="DESCRIPTION" lang ="fr" content="C-extra.com - Installing articles of various Unix softwares - BSD Linux Mac OSX">
<meta name="KEYWORDS" content="c-extra c-extra.com apache bind bsd compiling computer fedora freebsd installing linux mac osx mysql php linux samba webmin virtualmin">
<meta name="RATING" content="General">
<meta name="ROBOTS" content="index, follow">
<meta name="REVISIT-AFTER" content="1 Week">
<meta name="LANGUAGE" content="EN"> * Or an other localization
<!-- Meta Tags -->
</head>
<body>
</body>
</html>



This does not exclude the security principle and use of Files .htaccess with the Apache Web Server.


This stage, it remains to make the routing for example at Gandi and to configure the router and his firewall. But warning, does not serve the domain yet, with this intention, it is necessary to configure Bind. It will be another moment of pleasure...

Author
Eric Douzet
Début de page
bl br
C-extra.com v. 1.2.0 © 2003-2010, all rights reserved  -  Updated September 02, 2010 Infologism.com