Virtualhost cannot occur withing VirtualHost section

19,301

Solution 1

My first guess is that the file you're editing is being included by another file, but from inside a virtualhost directive or you just need to look at all the other files in your conf.d (especially the ones that get loaded before the one you're working on) and make sure that all of them are closing their virtualhost directives. If you try to do </virtualhost> in this extra config file, even though the apache worked before you started adding this new virtualhost, there's a good chance that the necessary </virtualhost> exists somewhere in a later file or inside the file that includes conf.d. An extraneous closing tag is just as invalid as a nested virtualhost, apparently.

Solution 2

First thing to do is put a </VirtualHost> directive immediately before your vhost definition e.g.

</VirtualHost>
<VirtualHost *:80>
    ServerName redmine.website.de
    ServerAdmin webmaster@localhost
    DocumentRoot /usr/share/redmine/public
</VirtualHost>

If that fixes the problem or you get a different error message then you have a <VirtualHost> without a closing </Virtualhost> somewhere in your config.

EDIT

The only way I can make your original error message occur is to have a complete

<VirtualHost *:80>
   ...
</VirtualHost> 

definition inside an include file which is included from within a <VirtualHost> definition.

Share:
19,301

Related videos on Youtube

UpCat
Author by

UpCat

Updated on September 18, 2022

Comments

  • UpCat
    UpCat over 1 year

    I can't set the vhost config for a subdomain. When I put something in it like

    <VirtualHost *:80>
        ServerName redmine.website.de
        ServerAdmin webmaster@localhost
        DocumentRoot /usr/share/redmine/public
    </VirtualHost>
    

    and reconfigure vhost I get the error message

    <VirtualHost> cannot occur within <VirtualHost> section
    

    I have look through every config file, apache2.conf, httpd.conf and through all files in /sites-xxx. The syntax is always correct.

    enter image description here

    When I put a </VirtualHost> at the top:

    enter image description here

    Any idea how I can solve this?

  • UpCat
    UpCat over 12 years
    Have a look at my updated question.
  • user9517
    user9517 over 12 years
    @ArtWorkAD: See my edit
  • UpCat
    UpCat over 12 years
    actually the vhost file I am editing is included by the the conf/http.include of the domain mysite.com. But I cant edit the http.include because it is generated by plesk every time I reconfigure vhost...
  • user4250202
    user4250202 over 12 years
    You may just need to look for a different way to add a virtualhost then. Can you do it from plesk?