# apache2 vhost config problems/questions [solved]

## Mgiese

hi there,

i got 2 dyndns adresses : test1.dyndns.org and test2.dyndns.org for example

i want to point 

test1.dyndns.org to /var/www/localhost/htdocs

and

test2.dyndns.org to /var/www/localhost/htdocs/test2

my /etc/apache2/vhosts.d/00_default_vhosts.conf looks like this :

```

# Host test1.dyndns.org

<VirtualHost *:80>

    DocumentRoot /var/www/localhost/htdocs/

ServerName test1.dyndns.org

</VirtualHost>

# Host test2.dyndns.org

<VirtualHost *:80>

    DocumentRoot /var/www/localhost/htdocs/test2

ServerName test2.dyndns.org

</VirtualHost>

```

but i am just receiving this error message either i use test1 or test2

```
Forbidden

You don't have permission to access / on this server.

Apache Server at test1.dyndns.org Port 80
```

or 

```
Forbidden

You don't have permission to access / on this server.

Apache Server at test2.dyndns.org Port 80
```

can someone give me a hint ? 

thanks in advance

----------

## DawgG

looks like dns and vhosts work ok, you just have to set up the permissions correctly (on the local dirs that contain the files for the web-content. i think the owner should be apache2 and the permissions 755 for testing. then take away as much as possible. for just serving "static" content read is enough, but for scripting languages execute must also be allowed.

for testing you can just put a small textfile in the webdirs and request it by its name with the browser, eg http://test2.dyndns.org/textfile

there is other tings you have to consider in your apache-config, eg is directory-listing allowed etc.

the cloesly check apache's logs and soon everything will work.

GOOD LUCK!

----------

## Mgiese

hi there, i honestly doubt that this is my problem ...

my configuration before was ONLY for "test1.dyndns.org" and it was pointing to "/var/www/localhost/htdocs" and it worked without any user right problems (but i did not use the vhosts, since it was not necessary for a single host, just used the default apache config) . i did'nt change a thing...

in both directories are index.html files

/var/...../htdocs/index.html

/var/.../htdocs/test2/index.html

any more suggestions ? thanks a lot !

btw : the user of all files in the htdocs dir is root .. and it worked flawlessly ..

----------

## malern

Try adding 

```
NameVirtualHost *:80
```

 to the start of your /etc/apache2/vhosts.d/00_default_vhosts.conf file.

If that doesn't work then check /var/log/apache/error_log for clues. What version of apache are you using?

----------

## eXess

There is a limitation in Apache 2.x that prevents the DocumentRoot of one Named Virtual Host to be inside the DocumentRoot of another Named Virtual Host. That could be the source of the problem you encounter with your "test2" website. For the "test" website, I really have no clue except the standard ones: 

- Did you check ownership/permissions on the files and directories in the DocumentRoot ? 

- Did you write <Directory> statements in Apache config files to allow user access to the files ? 

- Do you use other modules / extensions we should know of, such as SUExec or others ? 

If you want further help, it would be good if you could post your config files (beginning with httpd.conf) and additional information about version, modules, etc.

----------

## disi

Just set the permissions via <directory> in the config like:

```

# Host test1.dyndns.org

<VirtualHost *:80>

DocumentRoot /var/www/localhost/htdocs/

ServerName test1.dyndns.org

<Directory /var/www/localhost/htdocs/>

Order Deny,Allow

Allow from All

</Directory>

</VirtualHost> 

```

You don't use .htaccess somewhere burried in the folders?

----------

## Mgiese

 *disi wrote:*   

> Just set the permissions via <directory> in the config like:
> 
> ```
> 
> # Host test1.dyndns.org
> ...

 

THX a lot that did the trick !

----------

## Mgiese

what kind of directive do i need to specify a specific website/dir for ip adresses ? right now, test1.dyndns.org and test2.dyndns.org point to their specified location but if i try to reach the ip adress on which the apache runs i see the website of test1.dyndns.org... ?!?!

----------

## eXess

Use Apache docs ! 

http://httpd.apache.org/docs/2.0/vhosts/ip-based.html

And don't forget to update your Listen directive so that Apache listens on all IP addresses (Listen *:80 or Listen * is generally not a good idea, security-wise)

----------

## eXess

Addendum to my previous post : I don't get what you want to do. 

How can Apache tell which sub/virtual host you are trying to reach if you are just typing the IP address?? Right now, typing test1.dyndns.org or test2.dyndns.org results in your web browser resolving the IP, then connecting to that IP on port 80, then telling (at the server request) what is the name of the host it's trying to reach. If you type the IP in the browser, You would directly reach the host, and when the server requests the hostname, answer with the IP address, which the server does not understand and therefore it would display the default vhost (probably located in /var/www/htdocs/localhost or something like that)... 

You might want to assign multiple IP addresses to the machine (which requires quite a bit of network configuration) or multiple NICs (even worse) or use port-based virtual hosts, or use port forwarding in your router then multple IP-addresses on your host... 

If you really want to do that, we'll need more info...

----------

