Ubuntu (development) server - configuratie virtual hosts

Pagina: 1
Acties:

Acties:
  • 0 Henk 'm!

  • xAndyx
  • Registratie: Maart 2004
  • Laatst online: 27-03 13:04
Ik heb gisteren een 'oude server' gebruikt om er een ubuntu development server van te maken (12.04.2 - 32bit).

Deze heb machine heb ik hp-dev genoemd en apache + webmin werkt allemaal. Verder heb ik in onze dns server hp-dev.nl (verzonnen) laten doorverwijzen naar het ip adres van deze ubuntu machine en ik krijg de test pagina van apache te zien.

Ik krijg het niet voor elkaar om bijv abc.hp-dev.nl te laten kijken naar /websites/abc.hp-dev.nl/htdocs

De melding die apache eerst gaf was:
code:
1
2
* Restarting web server apache2                                                apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

Gefixt met:ServerName localhost toevoegen aan /etc/apache2/httpd.conf

Nu krijg ik nog de melding:
code:
1
[warn] NameVirtualHost *:80 has no VirtualHosts


En het subdomein werkt nog niet. :'(
Heeft iemand een tip?

Met bash script aangemaakte virtual host: /etc/apache2/sites-enabled/abc.hp-dev.nl
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<VirtualHost *>
        ServerName abc.hp-dev.nl
        DocumentRoot /websites/abc.hp-dev.nl/htdocs
        DirectoryIndex index.php
        ServerAdmin youremail@yourdomain.com
        ErrorLog "/var/log/apache2/abc.hp-dev.nl-error.log"
        CustomLog "/var/log/apache2/abc.hp-dev.nl.log" common

        <Directory "/websites/abc.hp-dev.nl/htdocs">
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all

        # ssi enabled
        AddType text/html .shtml
        AddOutputFilter INCLUDES .shtml
        Options +Includes
        </Directory>

</VirtualHost>


Om een site aan te maken gebruik ik dit (door mij aangepaste) bash script:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash

clear

subdomain=$1;
domainname="hp-dev.nl"; # Enter your domain name here, or set as second parameter ($2)
ava="/etc/apache2/sites-available";
ena="/etc/apache2/sites-enabled";

if [[ ${subdomain} == "" || ${domainname} == "" ]]; then
    echo "Usage: wpresshosts <subdomain>";
    echo "Example: wpresshosts www2";
    echo "  will install Wordpress and create the virtual host for www2.${domainname}";
    exit 0;
else
    echo "I am going to make Wordpress installs really easy for you!";
    echo "....................."
    echo "....................."
    vhost="${subdomain}.${domainname}";
fi

# Create http host
if [[ -e ${ava}/${vhost} ]]; then
    echo -e "\r\n";
    #echo "${ava}/${vhost} already exists. Skipping.";
elif [[ -e ${ena}/${vhost} ]]; then
    #echo "${ena}/${vhost} already exists. Skipping.";
    echo -e "\r\n";
else
    if [[ ! -e ${ava}/template.http ]]; then
        echo "${ava}/template.http does not exist. Cannot create ${ena}/${vhost}.";
    else
        cat ${ava}/template.http | sed "s/subdomain/${subdomain}/g" | sed "s/domainname/${domainname}/g" > ${ava}/${vhost}
    fi
fi

if [[ -e /websites/${vhost} ]]; then
    # Do nothing.
    echo "/websites/${vhost} exists.";
else
    sudo mkdir -p /websites/${vhost};
    sudo mkdir -p /websites/${vhost}/htdocs;
    sudo chown -R www-data /websites/${vhost};
    sudo chmod -R 755 /websites/${vhost};
    sudo chmod -R g+rw /websites/${vhost};
    sudo chmod -R g+s /websites/${vhost};
    echo -e "/websites/${vhost} has been created for you.\r\n";
fi

echo -e "Time to set up the database\r\n";
echo "Enter the name for the database:"
read dbname

echo "Enter the username for the database:";
read dbuser

echo "Enter the password for the user:";
read dbpassword

EXPECTED_ARGS=3
E_BADARGS=65
MYSQL=`which mysql`

Q1="CREATE DATABASE IF NOT EXISTS $dbname;"
Q2="GRANT ALL PRIVILEGES ON $dbname.* TO '$dbuser'@'localhost' IDENTIFIED BY '$dbpassword';"
Q3="FLUSH PRIVILEGES";
SQL="${Q1}${Q2}${Q3}"


echo -e "\r\nYou will need to enter your MySQL root user password to complete this process...\r\n";

$MYSQL -uroot -p -e "$SQL"

echo -e "The ${vhost} database has been created for you\r\n";
echo "....................."
echo -e ".....................\r\n"

bool="n";
echo -n "Should I enable ${ava}/${vhost}? (y/n)";
read bool;
if [[ ${bool} == "y" || ${bool} == "Y" || ${bool} == "yes" || ${bool} == "YES" || ${bool} == "Yes" ]]; then
    if [[ -e ${ena}/${vhost} ]]; then
        echo "Host was already enabled.";
    else
        if [[ ! -e ${ava}/${vhost} ]]; then
            echo "${ava}/${vhost} does not exist so I cannot enable it.";
        else
            echo "Running: cp ${ava}/${vhost} ${ena}/${vhost}";
            cp ${ava}/${vhost} ${ena}/${vhost};
        fi
    fi
else
    echo -e "\r\nYou will need to enable the virtual host manually (when you're ready)..\r\n";
    echo -e "sudo a2ensite ${vhost}\r\n";
fi

bool="n";
echo -n "Should I restart Apache? (y/n)";
read bool;
if [[ ${bool} == "y" || ${bool} == "Y" || ${bool} == "yes" || ${bool} == "YES" || ${bool} == "Yes" ]]; then
    echo -e "Running: service apache2 restart\r\n";
    sudo service apache2 restart;
else
    echo -e "\r\nRemember you will need to restart Apache for the new virtual host to take effect.\r\n";
    echo -e "sudo service apache2 restart\r\n";
fi

echo -e "OK, you're all set on the new virtual host!\r\n";
echo -e "Bye!\r\n";
echo "....................."
echo -e ".....................\r\n"

Acties:
  • 0 Henk 'm!

  • richardboer
  • Registratie: December 2005
  • Laatst online: 02-10 08:15
Volgens mij komt het doordat je in de virtualhost config geen *:80 maar alleen * gebruikt.
Als ik het tenminste vergelijk met de configs die ik heb staan voor de diverse virtualhosts.

Meen dat ik hier voorheen altijd ruzie mee had juist.

En de waarschuwing zegt het eigenlijk ook al he:
Hij zoekt naar een virtual host met: *:80 en vind deze niet

[ Voor 18% gewijzigd door richardboer op 25-06-2013 13:32 ]

Richard


Acties:
  • 0 Henk 'm!

  • Hero of Time
  • Registratie: Oktober 2004
  • Laatst online: 22:26

Hero of Time

Moderator LNX

There is only one Legend

Die error zegt al genoeg, waar richardboer 't over heeft. En let ook op je DirectoryIndex optie. Die zorgt ervoor dat je site niet geladen wordt als je geen index.php hebt. Zou je een simpel index.html hebben met als inhoud iets als dit, dan zie je natuurlijk niets:
HTML:
1
2
3
4
5
6
<html>
  <body>
    <h1>Welkom op ABC</h1>
    <p>Dit is de abc vhost.</p>
  </body>
</html>


Let ook op een mogelijke catch-all in de default vhost.

Commandline FTW | Tweakt met mate


Acties:
  • 0 Henk 'm!

  • xAndyx
  • Registratie: Maart 2004
  • Laatst online: 27-03 13:04
Bedankt voor de tips, heb mn template aangepast zodat onderstaande vhost genereert. En ik heb even een index.html geupload naar de map.

Subdomein abc.hp-dev.nl ook nog even apart toegevoegd in de dns records en nu doet ie het _/-\o_

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<VirtualHost *:80>
        ServerName abc.hp-dev.nl
        DocumentRoot /websites/abc.hp-dev.nl/htdocs
        DirectoryIndex index.html index.php
        ServerAdmin youremail@yourdomain.com
        ErrorLog "/var/log/apache2/abc.hp-dev.nl-error.log"
        CustomLog "/var/log/apache2/abc.hp-dev.nl.log" common

        <Directory "/websites/abc.hp-dev.nl/htdocs">
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all

        # ssi enabled
        AddType text/html .shtml
        AddOutputFilter INCLUDES .shtml
        Options +Includes
        </Directory>

</VirtualHost>