# Apache2+Vhosts+DynamicIP



## Demontager (May 8, 2011)

I have a question on setting up Apache on BSD, the system has installed quite recently, and first time for me, got  base systen set only, no GUI. There is a goal to move my own 2 websites there.

 I have two domains registered,  will mention here as mydomain.com and mydomain1.com, they should resolve to my IP. There is another small problem - I have a dynamic IP, but deal it with dyndns.org, I have configured own hostname as myhost.homelinux.com, if I ping it, it resolves my current IP. 

 This hostname is registered in the DSL router configuration and the router reports  IP changes on every IP changes to dyndns.

I set up Name Servers for  myhost.homelinux.com in zoneedit

```
Name Server: NS18.ZONEEDIT.COM
Name Server: NS4.ZONEEDIT.COM
```

In the domain control panel I put these NS for both domains. Then I configured  router to forward port 80 to the local BSDserver's IP - 192.168.1.5

 I need help in configuring Apache, so it can serve 2 virtual hosts.

 And  questions I have interest in:

1. What to be put in /etc/hosts on BSDserver? Apart from FreeBSD I have 3 computers and all taking Internet from one router.
  On all these computers exept BSDserver, I have set in /etc/hosts:


```
192.168.1.5 mydomain.com and mydomain1.com
```

2. How to configure httpd.conf? Especially interested in the field 
	
	



```
ServerName www.example.com:80
```
 I guess I should put myhost.homelinux.com there. Right?

My simplified config /usr/local/etc/apache22/httpd.conf (comments and some needed fields unhashed).

```
ServerRoot "/usr/local"

Listen 80

LoadModule authn_file_module libexec/apache22/mod_authn_file.so
LoadModule authn_dbm_module libexec/apache22/mod_authn_dbm.so
LoadModule authn_anon_module libexec/apache22/mod_authn_anon.so
LoadModule authn_dbd_module libexec/apache22/mod_authn_dbd.so
LoadModule authn_default_module libexec/apache22/mod_authn_default.so
LoadModule authn_alias_module libexec/apache22/mod_authn_alias.so
LoadModule authz_host_module libexec/apache22/mod_authz_host.so
LoadModule authz_groupfile_module libexec/apache22/mod_authz_groupfile.so
LoadModule authz_user_module libexec/apache22/mod_authz_user.so
LoadModule authz_dbm_module libexec/apache22/mod_authz_dbm.so
LoadModule authz_owner_module libexec/apache22/mod_authz_owner.so
LoadModule authz_default_module libexec/apache22/mod_authz_default.so
LoadModule auth_basic_module libexec/apache22/mod_auth_basic.so
LoadModule auth_digest_module libexec/apache22/mod_auth_digest.so
LoadModule file_cache_module libexec/apache22/mod_file_cache.so
LoadModule cache_module libexec/apache22/mod_cache.so
LoadModule disk_cache_module libexec/apache22/mod_disk_cache.so
LoadModule mem_cache_module libexec/apache22/mod_mem_cache.so
LoadModule dbd_module libexec/apache22/mod_dbd.so
LoadModule bucketeer_module libexec/apache22/mod_bucketeer.so
LoadModule dumpio_module libexec/apache22/mod_dumpio.so
LoadModule case_filter_module libexec/apache22/mod_case_filter.so
LoadModule case_filter_in_module libexec/apache22/mod_case_filter_in.so
LoadModule reqtimeout_module libexec/apache22/mod_reqtimeout.so
LoadModule ext_filter_module libexec/apache22/mod_ext_filter.so
LoadModule include_module libexec/apache22/mod_include.so
LoadModule filter_module libexec/apache22/mod_filter.so
LoadModule charset_lite_module libexec/apache22/mod_charset_lite.so
LoadModule deflate_module libexec/apache22/mod_deflate.so
LoadModule log_config_module libexec/apache22/mod_log_config.so
LoadModule log_forensic_module libexec/apache22/mod_log_forensic.so
LoadModule logio_module libexec/apache22/mod_logio.so
LoadModule env_module libexec/apache22/mod_env.so
LoadModule mime_magic_module libexec/apache22/mod_mime_magic.so
LoadModule cern_meta_module libexec/apache22/mod_cern_meta.so
LoadModule expires_module libexec/apache22/mod_expires.so
LoadModule headers_module libexec/apache22/mod_headers.so
LoadModule usertrack_module libexec/apache22/mod_usertrack.so
LoadModule unique_id_module libexec/apache22/mod_unique_id.so
LoadModule setenvif_module libexec/apache22/mod_setenvif.so
LoadModule version_module libexec/apache22/mod_version.so
LoadModule ssl_module libexec/apache22/mod_ssl.so
LoadModule mime_module libexec/apache22/mod_mime.so
LoadModule dav_module libexec/apache22/mod_dav.so
LoadModule status_module libexec/apache22/mod_status.so
LoadModule autoindex_module libexec/apache22/mod_autoindex.so
LoadModule asis_module libexec/apache22/mod_asis.so
LoadModule info_module libexec/apache22/mod_info.so
LoadModule cgi_module libexec/apache22/mod_cgi.so
LoadModule dav_fs_module libexec/apache22/mod_dav_fs.so
LoadModule vhost_alias_module libexec/apache22/mod_vhost_alias.so
LoadModule negotiation_module libexec/apache22/mod_negotiation.so
LoadModule dir_module libexec/apache22/mod_dir.so
LoadModule imagemap_module libexec/apache22/mod_imagemap.so
LoadModule actions_module libexec/apache22/mod_actions.so
LoadModule speling_module libexec/apache22/mod_speling.so
LoadModule userdir_module libexec/apache22/mod_userdir.so
LoadModule alias_module libexec/apache22/mod_alias.so
LoadModule rewrite_module libexec/apache22/mod_rewrite.so
LoadModule php5_module        libexec/apache22/libphp5.so

<IfModule !mpm_netware_module>
<IfModule !mpm_winnt_module>

User www
Group www

</IfModule>
</IfModule>


ServerAdmin you@example.com

ServerName www.example.com:80

DocumentRoot "/usr/local/www/apache22/data"


<Directory />
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

<Directory "/usr/local/www/apache22/data">

    Options Indexes FollowSymLinks

    AllowOverride None

    Order allow,deny
    Allow from all

</Directory>


<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>


<FilesMatch "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy All
</FilesMatch>


ErrorLog "/var/log/httpd-error.log"

LogLevel warn

<IfModule log_config_module>

    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "/var/log/httpd-access.log" combined
</IfModule>

<IfModule alias_module>


    ScriptAlias /cgi-bin/ "/usr/local/www/apache22/cgi-bin/"

</IfModule>

<IfModule cgid_module>
 
</IfModule>

<Directory "/usr/local/www/apache22/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>


DefaultType text/plain

<IfModule mime_module>
 
    TypesConfig etc/apache22/mime.types

 
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz


</IfModule>

# Virtual hosts
Include etc/apache22/extra/httpd-vhosts.conf

# Various default settings
Include etc/apache22/extra/httpd-default.conf


<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

Include etc/apache22/Includes/*.conf
```

3. How to describe virtual hosts in httpd-vhosts.conf? One website working on joomla other one - drupal. When installed from "ports" websites coming to /usr/local/www/mydomain.com and /usr/local/www/mydomain1.com, directory names joomla, drupal, I have changed  to my websites names respectively. I put these settings in /usr/local/etc/apache22/extra/httpd-vhosts.conf. Please correct me if wrong.


```
NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin [email]webmaster@mydomain.com[/email]
    DocumentRoot "/usr/local/www/mydomain.com"
    ServerName mydomen.com
    ServerAlias [url]www.mydomain.com[/url]
    ErrorLog "/var/log/mydomain.com-error_log"
    CustomLog "/var/log/mydomain.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email]webmaster@mydomain1.com[/email]
    DocumentRoot "/usr/local/www/mydomain1.com"
    ServerName mydomain1.com
    ErrorLog "/var/log/mydomain1.com-error_log"
    CustomLog "/var/log/mydomain1.com-access_log" common
</VirtualHost>
```


----------



## Demontager (May 9, 2011)

I have rewritten my httpd.conf http://pastebin.com/cXFdgNi0 and vhosts.conf include file.


```
NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin webmaster@mydomain.com
    DocumentRoot "/usr/local/www/mydomain"
    ServerName www.mydomain.com
    ErrorLog "/var/log/mydomain.com-error_log"
    CustomLog "/var/log/mydomain.com-access_log" common
<Directory "/usr/local/www/mydomain">
   Options Indexes FollowSymlinks MultiViews
   AllowOverride All
   Order allow,deny
   Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@mydomain1.com
    DocumentRoot "/usr/local/www/mydomain1"
    ServerName www.mydomain1.com
    ErrorLog "/var/log/mydomain1.com-error_log"
    CustomLog "/var/log/mydomain1.com-access_log" common

<Directory "/usr/local/www/mydomain1">
   Options Indexes FollowSymlinks MultiViews
   AllowOverride All
   Order allow,deny
   Allow from all
</Directory>

</VirtualHost>
```

But when I point from another system to http://www.mydomain1.com it goes to http://www.mydomain.com. What's wrong here?


```
BsdServer /etc/hosts
 ::1            localhost
127.0.0.1        localhost
192.168.1.5 [url]www.mydomain.com[/url] [url]www.mydomain1.com[/url] free-snich
```


----------



## AndyUKG (May 9, 2011)

Hi,

  first off, to simplify your life and debugging the issue, what is in /etc/hosts is not important so you can forget about that causing you a problem.

What you have now looks fine on the face of it, does `# apachectl -t` come back without any errors? You have restarted or HUP'd the HTTPD daemons too of course?
One common mistake is people get confused between addresses starting with and without *"www."*. To be safe you can avoid these issues by using *"ServerAlias"* like this:


```
<VirtualHost *:80>
    ServerAdmin webmaster@mydomain.com
    DocumentRoot "/usr/local/www/mydomain"
    ServerName www.mydomain.com
    ServerAlias mydomain.com
</VirtualHost>
```

thanks Andy.


----------



## Demontager (May 10, 2011)

*AndyUKG*, thanks, the problem was in "www" as you told, now all fine.

Only one problem remained with one domain - it is not working from the Internet. I will discuss real domain names which I own to be clear in problem.

So, I got two own domains max-cook.com and nixtalks.com, but only the first one works. These two domains have the same NS. Also I got dynamic IP, so I use dyndns.org and it monitors my IP changes, config is http://s011.radikal.ru/i315/1105/05/3cfbca5c709e.jpg,

And also I use zoneedit to get NS for domain registered in dyndns, settings are http://s50.radikal.ru/i129/1105/3c/19df380b5857.jpg.

So max-cook.com works fine with that config, dig shows http://pastebin.com/0SJ1ppEL And nixtalks.com does not, dig shows http://pastebin.com/3JP5x7DY.

P.s. 192.168.1.1 my router config, settings for dyndns.org are there, so every time my IP changes it updates it to dyndns. How to make nixtalks.com work as well?


----------



## AndyUKG (May 10, 2011)

Just had a look on dig, looks like both sites are registered correctly in DNS now...

ta Andy.


----------



## Demontager (May 11, 2011)

Yes, I didn't create one more zone for second domain. All fine now, thanks!


----------

