Create VirtualHost for domains

3

I have 26 virtual-host for subdomains (they were created type A, not CNAME type) of a page with domain "example1.com" (the domain was not being used) and I need to create the virtualhost to that domain

In% /etc/apache2/sites-available/ these 26 virtualhost have this form:

<VirtualHost subdomain1.ejemplo1.com:80>
    ServerAdmin <[email protected]_example.com>
    DocumentRoot /var/www/html/subdomain1/

    WSGIScriptAlias / /var/www/html/subdomain1/django.wsgi

    Alias /static/ /var/www/html/subdomain1/static/

    <Directory /var/www/html/subdomain1>
    Order allow,deny
    Allow from all
    </Directory>

    <Directory /var/www/html/subdomain1/static>
    Order allow,deny
    Allow from all
    </Directory>

    ServerName subdomain1.ejemplo1.com

I also made the mistake of editing the 000-default.conf

<VirtualHost *:80>
    ServerAdmin <[email protected]_example.com>
    #ServerName ejemplo1.com
    #ServerAlias www.ejemplo1.com
    DocumentRoot /var/www/html/ejemplo1_com/

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

But you have not taken the contents of that folder

In /etc/hosts I have this:

127.0.0.1       localhost  
ip_example1     otro_name_host        nombre_empresa  
::1     localhost ip6-localhost ip6-loopback  
ff02::1 ip6-allnodes  
ff02::2 ip6-allrouters  

Sincerely I do not know what those parameters are, that configuration was already like this.

I need 2 things: 1. correct the 000-default.conf or delete it and create a ejemplo1_com.conf 2. create a ejemplo2_com.conf (it's another totally different domain) and its virtualhost. Adding your info to /etc/hosts

    
asked by Diana Carolina Hernandez 27.01.2016 в 18:33
source

2 answers

5

You have not given much detail about your current configuration but on the Apache page there are several examples that can surely help you.

  • Run several sites by name at the same IP address:

    # Asegurar que Apache escuche en el puerto 80
    Listen 80
    <VirtualHost *:80>
        DocumentRoot "/www/example1"
        ServerName www.example.com
    
        # Otras directivas
    </VirtualHost>
    
    <VirtualHost *:80>
        DocumentRoot "/www/example2"
        ServerName www.example.org
    
        # Otras directivas
    </VirtualHost>
    
  • Sites by name in more than one IP address:

    Listen 80
    
    # Este es el servidor principal corriendo en 172.20.30.40
    ServerName server.example.com
    DocumentRoot "/www/mainserver"
    
    <VirtualHost 172.20.30.50>
        DocumentRoot "/www/example1"
        ServerName www.example.com
    
        # Otras directivas
    </VirtualHost>
    
    <VirtualHost 172.20.30.50>
        DocumentRoot "/www/example2"
        ServerName www.example.org
    
        # Otras directivas
    </VirtualHost>
    
  • Run different sites in different ports:

    Listen 80
    Listen 8080
    
    <VirtualHost 172.20.30.40:80>
        ServerName www.example.com
        DocumentRoot "/www/domain-80"
    </VirtualHost>
    
    <VirtualHost 172.20.30.40:8080>
        ServerName www.example.com
        DocumentRoot "/www/domain-8080"
    </VirtualHost>
    
    <VirtualHost 172.20.30.40:80>
        ServerName www.example.org
        DocumentRoot "/www/otherdomain-80"
    </VirtualHost>
    
    <VirtualHost 172.20.30.40:8080>
        ServerName www.example.org
        DocumentRoot "/www/otherdomain-8080"
    </VirtualHost>
    
  • IP-based virtual sites:

    Listen 80
    
    <VirtualHost 172.20.30.40>
        DocumentRoot "/www/example1"
        ServerName www.example.com
    </VirtualHost>
    
    <VirtualHost 172.20.30.50>
        DocumentRoot "/www/example2"
        ServerName 
    </VirtualHost>
    

For more examples:

Update

About the file /etc/hosts , if you are not using IPv6 you can leave this part as it is currently:

::1     localhost ip6-localhost ip6-loopback  
ff02::1 ip6-allnodes  
ff02::2 ip6-allrouters  

The operation of /etc/hosts is very simple, if you have already raised the Apache service and do something like this for test purposes:

127.0.0.1   localhost
127.0.0.1   example.com

You can access these URLs and the Apache service will recognize them:

Please note that link is a true site but it is an example to show how Apache works and /etc/hosts .

Having said this, what you need to do is configure according to the rules you have defined for VirtualHost :

127.0.0.1   localhost
127.0.0.1   subdomain1.ejemplo1.com ejemplo1.com
127.0.0.1   subdomain2.ejemplo2.com ejemplo2.com
127.0.0.1   subdomain3.ejemplo3.com ejemplo3.com
# ...
    
answered by 27.01.2016 в 19:55
1

Try a configuration like this:

sudo nano /etc/apache2/sites-available/ejemplo1.conf

And you add:

<VirtualHost *:80>

    ServerAdmin [email protected]
    ServerName example1.com
    ServerAlias www.example1.com

    DocumentRoot /var/www/html/ejemplo1_com/

</VirtualHost>

Then do not forget:

To tell apache to activate the virtualhost

a2ensite ejemplo1

Then restart the apache2 service

service apache2 restart
    
answered by 27.01.2016 в 21:45