简体   繁体   中英

DigitalOcean Apache 2 Debian 7 Virtual Host for subdomain

I have VPS on digitalocean.com. To DNS for example.com I added cname subdomain.

Server work on Debian 7 with apache 2.2 and php 5.5

I have problem with subdomain configuration. I tried all tutorial form first 4 google pages for "apache subdomain configuration".

But still after request subdomain.example.com response is example.com content.

I use:

apachectl -t -D DUMP_VHOSTS

Result is:

    apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[Thu Nov 28 15:58:58 2013] [warn] VirtualHost xxx.xxx.xx.xxx:80 overlaps with VirtualHost xxx.xxx.xx.xxx:80, the first has precedence, perhaps you need a NameVirtualHost directive
[Thu Nov 28 15:58:58 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
VirtualHost configuration:
xxx.xx.xxx.xxx:80     subdomain.example.com (/etc/apache2/sites-enabled/subdomain.example.com:1)
127.0.0.1:80           xxx.xxx.xx.xxx (/etc/apache2/sites-enabled/000-default:1)
xxx.xxx.xx.xxx:80      example.com (/etc/apache2/sites-enabled/example.com:1)

/etc/apache2/sites-available/example.com I have link i sites-enabled

<VirtualHost xxx.xxx.xx.xxx:80>
  ServerName  example.com
  ServerAdmin email@email.com
  DocumentRoot /var/www/example.com

  <Directory /var/www/example.com>
<IfModule sapi_apache2.c>
        php_admin_flag engine on
    </IfModule>
    <IfModule mod_php5.c>
        php_admin_flag engine on
    </IfModule>
    Options Includes FollowSymLinks MultiViews
    AllowOverride All
    DirectoryIndex index.php index.html index.html5
  </Directory>

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

  ErrorDocument 404 /404/

  SetOutputFilter DEFLATE
  SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|ico|png)$ \ no-gzip dont-vary
  SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ \no-gzip dont-vary
  SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary

  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

</VirtualHost>

/etc/apache2/sotes-available/subdomain.example.com I have link in sites-enabled

:80>
  ServerName  subdomain.example.com
  ServerAdmin mail@mail.com
  DocumentRoot /var/www/subdomain.example.com
 ServerAlias subdomain.example.com
  <Directory /var/www/subdomain.example.com>
<IfModule sapi_apache2.c>
        php_admin_flag engine on
    </IfModule>
    <IfModule mod_php5.c>
        php_admin_flag engine on
    </IfModule>
    Options Includes FollowSymLinks MultiViews
    AllowOverride All
    DirectoryIndex index.php index.html index.html5
  </Directory>

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

  ErrorDocument 404 /404/

  SetOutputFilter DEFLATE
  SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|ico|png)$ \ no-gzip dont-vary
  SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ \no-gzip dont-vary
  SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary

  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

</VirtualHost>

I tried too with ServerAlias, foledrs in /var/www have owner as www-data and 755 chmod.

Thanks in advance for any idea.

Regards

as you can see in your 2nd block, you are missing the this:

<VirtualHost xxx.xxx.xx.xxx:80>

and that should be configured at the beginning. you need to have your server's fully qualified domain name by doing this: if you use root as user, then: nano /etc/hosts

then add this:

127.0.0.1       localhost

#Virtual Hosts 
12.34.56.789    example.com

then save it and restart Apache, and you're done.

All you have to do is adding subdomain record to your domain you assigned. to do so, follow the tutorial on their site at: How To Set Up and Test DNS Subdomains with DigitalOcean's DNS Panel

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM