Configuration of Multiple Apache Virtual Hosts in Ubuntu

Source: Internet
Author: User

In ubuntu, the path of the Apache configuration file is/etc/apache2. In this directory, You can see http. conf, but the file is empty. In ubuntu, Apache configuration is dispersed to various configuration files. The apache2.conf file in this directory is a general configuration file. In this file, you can see the include command, it includes many other files, including HTTP. conf. Therefore, configuration writing in HTTP. conf also takes effect.

The following is an example of the configuration of multiple virtual hosts. I have two machines, one for Windows, IP: 192.168.1.105, one for Ubuntu, and IP: 192.168.1.115. Now I have two websites running on Ubuntu for development, named phptest and dbmanage respectively, what if I access it through windows?

In the apache2.conf file, you can see

In fact, sites-enabled is a sing of sites-available, so we can configure it in the sites-available Directory. Copy a default file under sites-available, name it phptest, and change the phptest file. The phptest file is as follows:

 1 <VirtualHost *:80> 2     ServerAdmin webmaster@localhost 3     ServerName phptest 4     ServerAlias www.phptest.com 5     DocumentRoot /home/dingjing/web/www 6     <Directory /> 7         Options FollowSymLinks 8         AllowOverride All 9     </Directory>10     <Directory /home/dingjing/web/www>11         Options Indexes FollowSymLinks MultiViews12         AllowOverride All13         Order allow,deny14         allow from all15     </Directory>16 17     ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/18     <Directory "/usr/lib/cgi-bin">19         AllowOverride None20         Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch21         Order allow,deny22         Allow from all23     </Directory>24 25     ErrorLog ${APACHE_LOG_DIR}/error.log26 27     # Possible values include: debug, info, notice, warn, error, crit,28     # alert, emerg.29     LogLevel warn30 31     CustomLog ${APACHE_LOG_DIR}/access.log combined32     <IfModule mod_rewrite.c>33         RewriteEngine on34         RewriteCond %{REQUEST_FILENAME} !-f35         RewriteCond %{REQUEST_FILENAME} !-d36         RewriteRule !\.(js|ico|gif|jpg|png|css|xml|swf|cur)$ /index.php [NC]37     </IfModule>38 39     Alias /doc/ "/usr/share/doc/"40     <Directory "/usr/share/doc/">41         Options Indexes MultiViews FollowSymLinks42         AllowOverride All43         Order deny,allow44         Deny from all45         Allow from 127.0.0.0/255.0.0.0 ::1/12846     </Directory>47 48 </VirtualHost>

Servername is the server name, serveralias is the alias, and DocumentRoot is the file directory of the website. In this configuration file, we have enabled rewrite rules. For details, see the configuration in line 32-37.

The name-based VM must be configured with namevirtualhost *: 80. You can write this statement in the/etc/apache2/ports. conf file. In the same way, you can create a dbmanage file, which is not described here.

In this case, the file configuration is complete, but the newly added file is not mapped to the sites-enable directory. To add the ing, run:

In this case, the corresponding configuration file is in the sites-enable directory, and the dbmanage file is added in the same step.

In Windows, configure hosts:

In this way, you can access these two websites in windows.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.