Ubuntu apache2 under the directory structure.

Source: Internet
Author: User
Tags plone

Under Windows, Apache's configuration file is usually only one, which is httpd.conf. But when I installed Apache2 with the Apt-get install apache2 command on Ubuntu Linux, I found that its httpd.conf (located in the/etc/apache2 directory) was empty. It turns out that the configuration file for Ubuntu's Apache software package is not as simple as windows, and that it looks complicated by splitting the settings into different profiles, but it's really reasonable to think about the design.

Strictly speaking, Ubuntu's Apache configuration file is/etc/apache2/apache2.conf,apache to automatically read the configuration information for this file at startup. Other configuration files, such as httpd.conf, are included through the include directive. These include lines can be found in apache2.conf:


# Include Module Configuration:

# Include All the user configurations:

# Include Ports Listing
# Include Generic snippets of statements

# Include The virtual host configurations:
Combined with annotations, you can clearly see the overall effect of each configuration file. Of course, you can put all the settings in apache2.conf or httpd.conf or any configuration file. This division of Apache2 is only a good habit.

The most important thing after you install Apache is to know where the Web document root directory is, and for Ubuntu, the default is/var/www. How do you know that? There is no documentroot in the apache2.conf, httpd.conf is empty, so it must be in the other files. After the search, found in the/etc/apache2/sites-enabled/000-default, there is such content:


Namevirtualhost *
<virtualhost *>
ServerAdmin Webmaster@localhost

This is set up a virtual host, it doesn't make sense to me. So I commented out the include/etc/apache2/sites-enabled/line in apache2.conf, and in httpd.conf I set DocumentRoot to a directory in my user directory so it was easy to develop.

And look at what's in the/etc/apache2 catalogue. Just now found in the apache2.conf sites-enabled directory, and under/etc/apache2 there is a sites-available directory, which is put what. In fact, this is the real configuration file, and the sites-enabled directory to store just a few points to the file here the symbolic link, you can use ls/etc/apache2/sites-enabled/to confirm. So, if you have more than one virtual host configured on Apache, each virtual host's configuration file is placed under Sites-available, so it is very convenient to disable and enable the virtual host: When creating a link to a virtual host profile under Sites-enabled , it is enabled, if you want to shut down a virtual host, simply delete the corresponding link, you do not have to change the configuration file.

Mods-available, mods-enabled and the above sites-available, sites-enabled similar, the two directories are stored in the Apache function module configuration files and links. When I installed the PHP module with apt-get install PHP5, I had php5.load, php5.conf, and links to these two files in both directories. This catalog result is very handy for enabling and deactivating a certain Apache module.

The last one to say is ports.conf, which sets the port used by Apache. If you need to adjust the default port settings, it is recommended that you edit this file. Or you think it is superfluous, you can first apache2.conf in the include/etc/apache2/ports.conf line out, in the httpd.conf set Apache port.

The default installed directory structure in Ubuntu is a little different. The configuration of module and virtual host in Ubuntu has two directories, one is available, the other is enabled,available directory is stored valid content, but does not work, only use LN to enable the past can function. It's easy to use for debugging, but if you don't know beforehand, it's a bit of a hassle to find.

/etc/apache2/sites-available is placed in the VH configuration, but does not work, to the file link to the sites-enabled directory.

4. Restart command
Sudo/etc/init.d/apache2 Restart or
sudo apache2-k restart
Stop stopping; Start start 5. log files in/var/log/apache2/

Turn from: http://www.phpchina.com/home/space.php?uid=31261&do=blog&id=41851

A basic configuration

We all know that if we want to set more than one domain name or hostname on a single machine, we need to use the name-based virtual master

Machine. So how do you set it up? This is the problem that this guide is trying to solve. In Ubuntu's/etc/apache2/eye

A Apache2 master configuration file apache2.conf is recorded. In this file we can see this line of content:


This line means that the file contains a filename in the/etc/apache2/sites-enabled/directory that does not contain the "." or "#"

Two characters for all files. And when we list the files for that directory, we find that there is only one 000-default soft link file

, the actual connection is the default file in the/etc/apache2/sites-available directory, it is not difficult to see the text of the file

The name does not contain "." or "#". So this file is, of course, to be included in the config file apache2.conf. Play

Open the file and find that it is actually a configuration file for a virtual host, but because the virtual host in the file is *, it

is a common configuration file on the Internet. If we want to set up a virtual host, then we need to change the file to look like the following:



ServerName www.britepic.org

ServerAdmin Ubuntu@gmail.com



Options FollowSymLinks

AllowOverride None



Options Indexes followsymlinks MultiViews

AllowOverride None

Order Allow,deny

Allow from all

# This directive allows us to have apache2 ' s default start Page

# in/apache2-default/, but still have/go to the right place

# commented out for Ubuntu

#RedirectMatch ^/$/apache2-default/



<directory "/usr/lib/cgi-bin" >

AllowOverride None

Options execcgi-multiviews SymLinksIfOwnerMatch

Order Allow,deny

Allow from all



# Possible values Include:debug, info, notice, warn, error, crit,

# Alert, Emerg.

LogLevel warn

Customlog/var/log/apache2/access.log combined

Serversignature on


<directory "/usr/share/doc/" >

Options Indexes multiviews FollowSymLinks

AllowOverride None

Order Deny,allow

Deny from all

Allow from 1/128



Let's take a look at the settings in the above setting that are related to the virtual host:

' Namevirtualhost ': What we want to do is a virtual host based on the name, and its IP address is

' <virtualhost> and </VirtualHost> ': Represents the configuration of a virtual host in which

' ServerName www.britepic.org ': Setting the domain name of the virtual host

' ServerAdmin Ubuntu@gmail.com ': Set up mail for this virtual host network administrator

' documentroot/var/www/': Setting the home directory path for this virtual host

' Errorlog/var/log/apache2/error.log ': Set error message for this virtual host

' Customlog/var/log/apache2/access.log combined ': Set access information for this virtual host

This allows us to configure a virtual host www.britepic.org. But since this is the default configuration, restart in Apache2

After that, whether you enter any domain name in the DNS server that points to the host, it will be directed www.britepic.org this

/var/www This directory that the default configuration points to. Unless the domain name is used by other virtual host configurations, such as we also configure

The edunuke.britepic.org point to the native, and the corresponding virtual host is configured, so enter the domain name

Edunuke.britepic.org will be in the directory where the domain name should be.

B further Notes

To clarify that we add a virtual host site edunuke.britepic.org, first to

Create a file Edunuke in the/etc/apache2/sites-available/directory. Of course, there is no "." In this file name.

or "#" of these two characters. Then edit the file:


ServerName edunuke.britepic.org

ServerAdmin Ubuntu@britepic.org

DocumentRoot "/var/www/edunuke/"

ErrorLog "/var/log/apache2/edunuke_errors.log"

Customlog "/var/log/apache2/edunuke_accesses.log" common


The specific meaning of the set is similar to the above, which I will not say more. And then run the command again:

sudo a2ensite Edunuke

In this case, the virtual host site edunuke.britepic.org has been installed. At this point you can also

The/etc/apache2/sites-enabled/directory found one more to/etc/apache2/sites-available/edunuke

of soft links. The next step is to restart the Apache2 to run the virtual host site:

Sudo/etc/init.d/apache2 restart

If you type edunuke.britepic.org in the browser, you will be directed to the/var/www/edunuke directory, and

Entering other domain names pointing to the local computer will refer to the/var/www directory in the default configuration. A friend who is familiar with Apache2 will ask

Why such trouble, put in a file is not also OK. Why do you use two files? is actually very simple, because if

When I want to maintain the Edunuke site, I just run the command:

sudo a2dissite Edunuke

Sudo/etc/init.d/apache2 restart

, this can maintain Edunuke this site, but also does not affect the normal operation of other sites.

It talks about a simple virtual host configuration method. This basically meets most of our needs. But if you install

With Zope Plone, the above setting is far from enough because the Zope Plone structure uses a port that is not 80

Port, so we have to do port redirection. To be able to do this, we have to activate the Rewrite and Proxy two modules.

Activation module is simple, like the site configuration directory, in the APACHE2 also has two module configuration directory: mods-available

and mods-enabled. In the Mods-available directory are all the available modules, and in the mods-enabled directory

Is the module that has been installed into the Apache2. Since there are already Rewrite in the mods-available directory and

Proxy module's configuration boot file, so simply install it into Apache2. To use the command:

sudo a2enmod rewrite

sudo a2enmod proxy

Then, add the virtual host site plone.britepic.org and create similar Edunuke sites

Create a file Plone in the/etc/apache2/sites-available/directory. Apparently there is no "." In this file name.

or "#" of these two characters. Then edit the file:


ServerName plone.britepic.org

ServerAdmin Ubuntu@britepic.org

ErrorLog "/var/log/apache2/plone_errors.log"

Customlog "/var/log/apache2/plone_accesses.log" common

Rewriteengine on

Rewriterule ^/(. *)


/$1 [L,p]

<proxy *>

Order Deny,allow

Deny from all

Allow from all



This installs the Plone.britepic.org virtual host site, which you can enter in the address bar in the browser

Http://plone.britepic.org can redirect to the Zope Plone site (Executive Editor: Easy Home Electronics)

Turn from: http://www.ejdz.cn/wangzhankaifa/Ubuntu_Apache_jyymddzdsz_2486.htm

System version: Ubuntu 10.04 (View command for cat /etc/issue or sudo lsb_release -a)

Apache Current version: 2.2.14 (with view)

Under Ubuntu, the configuration files provided by the package are located in the/etc/apache2 directory after the command sudo apt-get install apache2 installation is complete:

01 02 03 04 05 06 07 08 09 10 11-12 Miao@ubuntu:/etc/apache2 $ ls-l Total 68-rw-r--r--1 root 8113 2010-04-14 04:20 apache2.conf drwxr-xr-x 2 root Root 4096 2010-06-02 01:08 conf.d-rw-r--r--1 root root 725 2010-04-14 04:20 envvars-rw-r--r--1 root root 0 2 010-06-02 00:54 httpd.conf-rw-r--r--1 root 31063 2010-04-14 04:20 Magic drwxr-xr-x 2 root root 4096 2010-06-02 0 1:27 mods-available drwxr-xr-x 2 root 4096 2010-06-02 00:57 mods-enabled-rw-r--r--1 root root 750 2010-04-14 0 4:20 ports.conf drwxr-xr-x 2 root 4096 2010-06-02 01:31 sites-available drwxr-xr-x 2 root root 4096 2010-06-02 00 : sites-enabled


To view this profile as the primary profile for the APACHE2 server, you will find the following

01 02 03 04 05 06 07 08 09 10 11 12-13 # Include Module Configuration:include/etc/apache2/mods-enabled/*.load include/etc/apache2/mods-enabled/*.conf # INC Lude all the user configurations:include/etc/apache2/httpd.conf # Include ports Listing include/etc/apache2/ports.co   NF # include generic snippets of statements include/etc/apache2/conf.d/[^.#]* # include generic snippets of statements include/etc/apache2/conf.d/# Include The virtual host configurations:include/etc/apache2/sites-enabled/

This is visible, apache2 according to the different configuration function, the configuration file is segmented, this is more conducive to management


As an additional fragment of the configuration file, by default, only charset fragments are provided,

1 2 Miao@ubuntu:/etc/apache2/conf. d$ Cat CharSet #AddDefaultCharset UTF-8

If necessary, we can modify the default encoding to GB2312, that is, the contents of the file is: Adddefaultcharset GB2312


It's an empty file.


The file contains data about the Mod_mime_magic module, and generally does not need to be modified.

01 02 03 04 05 06 07 08 09 10 11 12 13-14 # The format is 4-5 columns:  #    Column #1: Byte to begin checking from, > indicates CO ntinuation  #    column #2: Type of data to match  #    column #3: contents of Dat A to match  #    column #4: MIME type of result  #    column #5: MIME encoding of Result (optional)   #-------------------------------------------------------# localstuff:  file (1) Magic For locally observed files  # ADD no locally observed files here.  # real Audio (Magic. ra\0375)   0 & nbsp;     belong          0x2e7261fd       audio/x-pn-realaudio  0       string          . rmf            application/vnd.rn-realmedia  0      &nBsp string  mas_utrack_v00  >14     string  >/0              Audio/x-mod


A configuration file that listens for IP and port settings for the server.

1 2 3 Miao@ubuntu:/etc/apache2 $ cat ports.conf namevirtualhost *:80 Listen 80


The directory is a few. conf and. Load files, which are the configuration files that can be used in the system to load various modules, while the mods-enabled directory is a symbolic connection to these profiles, as you can see from the configuration file apache2.conf The system loads the module through the mods-enabled directory, that is, the system loads the module only through a configuration file in the Mods-available directory where the symbolic connection is created under this directory. The system also provides two commands a2enmod and a2dismod to maintain these symbolic connections. These two commands are provided by the Apache2-common package. Commands are also very simple:a2enmod [Module] or a2dismod [module]


Directory for the configuration of the site configuration files, sites-enabled directory is a symbolic connection to these profiles, the system through these symbolic connections to the site sites-enabled Directory of symbolic connections with a number prefix , such as 000-default, this number is used to determine the boot sequence, the smaller the number, the higher the boot priority. The system provides two commands A2ensite and a2dissite to maintain these symbolic connections. These two commands are provided by the Apache2-common package.


By default, the page file to be published should be placed under the /var/www directory, which can be modified with the documnetroot option in the main configuration file.

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.