Ubuntu apache2 configuration details

Source: Internet
Author: User
Tags fully qualified domain name

In Windows, there is usually only one configuration file for Apache, that is, httpd. conf. However, after I installed apache2 with the apt-Get install apache2 command in Ubuntu Linux, I found that its httpd. conf (in the/etc/apache2 directory) is empty! It is found that the configuration file of the Apache package in Ubuntu is not as simple as that in windows. It divides the configuration items into different configuration files and looks complicated, but think about the design carefully.

Strictly speaking, the Apache of ubuntu (or the Apache under Linux? The configuration file of other Apache software packages is/etc/apache2/apache2.conf. Apache automatically reads the configuration information of this file at startup. Some other configuration files, such as httpd. conf, are included through the include command. You can find these include rows in apache2.conf:

# Include module configuration:
Include/etc/apache2/mod-enabled/*. Load
Include/etc/apache2/mod-enabled/*. conf

# Include all the user invocations:
Include/etc/apache2/httpd. conf

# Include ports listing
Include/etc/apache2/ports. conf
......
# Include generic snippets of statements
Include/etc/apache2/CONF. d/

# Include the virtual host configurations:
Include/etc/apache2/sites-enabled/

With Comments, you can clearly see the general functions of each configuration file. Of course, you can put all the settings in apache2.conf, httpd. conf, or any configuration file. This classification of apache2 is just a good habit.

The most important thing after installing Apache is to know where the web document root directory is. For Ubuntu, the default value is/var/www. How do you know? There is no DocumentRoot entry in apache2.conf, and httpd. conf is empty, so it must be in other files. After searching, it is found that the content in/etc/apache2/sites-enabled/000-default contains the following content:

Namevirtualhost *
<Virtualhost *>
Serveradmin webmaster @ localhost

DocumentRoot/var/www/
......

This is for setting up a VM, Which is meaningless to me. So I commented out the include/etc/apache2/sites-enabled/line in apache2.conf and added it to httpd. in Conf, set DocumentRoot to a directory under my user directory to facilitate development.

Let's take a look at the things in the/etc/apache2 directory. I just found the sites-enabled directory in apache2.conf, and there is a sites-available directory under/etc/apache2. What is the content here? In fact, this is the real configuration file, and the sites-enabled directory stores only some symbolic links pointing to the files here, you can use ls/etc/apache2/sites-enabled/to confirm it. Therefore, if multiple virtual hosts are configured on Apache and the configuration files of each virtual host are stored in sites-available, it is very convenient to disable and enable the Virtual Host: when sites-enabled is used to establish a chain pointing to a virtual host configuration file
It is enabled when it is connected. To disable a virtual host, you only need to delete the corresponding link and do not need to modify the configuration file.

========================================================== ====================

The following two directories are used to store the configuration files and links of the Apache function module. After I installed the PHP module with APT-Get install PhP5, php5.load, php5.conf, and links to these two files are available in these two directories. This directory result is very convenient for enabling or disabling an Apache module.

The last one is ports. conf, where the port used by Apache is set. To adjust the default port settings, we recommend that you edit this file. Alternatively, you can remove the include/etc/apache2/ports. conf line in apache2.conf and set the Apache port in httpd. conf.

The default directory structure installed in Ubuntu is quite different. In ubuntu, the module and virtual host configurations both have two directories: available, enabled, and available. The available Directory stores valid content but does not work, it takes effect only when Ln is connected to enabled. Debugging is easy to use, but if you do not know it beforehand, it will be a little troublesome to find it.

The/etc/apache2/sites-available file is configured with the link-to-enabled file but does not work. You must link the file to the sites-enabled directory.

<Virtualhost *>

Servername Domain Name

 

DocumentRoot treats the public in the rails project as the root directory

<Directory public root directory>

Options execcgi followsymlinks

AllowOverride all

Allow from all

Order allow, deny

</Directory>

Errorlog/var/log/apache2/error-Domain Name. Log

</Virtualhost>

========================================================== ================

 

What is virtual hosting )?
Simply put, the same server can process more than one domain at the same time ). Assume that both www.example1.net and www.example2.net point to the same server, and web servers support virtual hosting. Then www.example1.net and www.example2.net can access different web spaces (website file storage directory) on the same server ).

 

Configuration format

In apache2, all valid site information is stored in/etc/apache2/sites-available/User Name (file. We can add the following information to add a valid virtual space. Just copy most of the items in default. Remember to change DocumentRoot as the default directory and set the path in directory, note that the port number must not be the same as that of other virtual hosts:

<Virtualhost * Custom port>
# Add your website name after servername
Servername www.linyupark.com
# If you want to obtain the same website name for multiple websites, add another website alias after serveralias.
# Aliases are separated by spaces.
Serveralias ftp.linyupark.com mail.linyupark.com
# Add the email address of the website administrator after serveradmin to contact the website administrator if any problem occurs.
Serveradmin webmaster@linyupark.com
# Add the directory path for storing website content after DocumentRoot (user's personal directory)
DocumentRoot/home/linyupark/public_html
<Directory/home/linyupark/public_html>
Options indexes followsymlinks Multiviews
AllowOverride none
Order allow, deny
Allow from all
</Directory>
ScriptAlias/cgi-bin // usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride none
Options execcgi-Multiviews + symlinksifownermatch
Allow from all
</Directory>
Errorlog/home/linyupark/public_html/error. Log
# Possible values include: Debug, info, notice, warn, error, crit,
# Alert, emerg.
Loglevel warn
Customlog/home/linyupark/public_html/access. Log combined
Serversignature on
</Virtualhost>

If your server has multiple IP addresses and different IP addresses have different virtual users, you can change them:

<Virtualhost IP Address [: Port]>
...
</Virtualhost>

Enable Configuration

The content we configured above is only "valid" virtual host. If it works, put it in the/etc/apache2/sites-enabled folder. We can use the ln command to create a pair of associated files:

Sudo ln-S/etc/apache2/sites-available/linyupark/etc/apache2/sites-enabled/linyupark

Check the syntax and restart the web service.

To be cautious, check the syntax before restarting the service:

sudo apache2ctl configtest

If no error occurs, restart Apache.

sudo /etc/init.d/apache2 -k restart

 

View results

The main setting has been completed. It's still easy. ^_^. What is the effect?

It is also simple. You only need to modify the host table on the host (XP is used. The address is:

Windows/system32/Drivers/etc

After opening, add the following sentence:

192.168.1.22 www.linyupark.com

In the browser, enter www.linyupark.com and go to the IP address 192.168.1.22 server to receive the request. Check whether the Domain Name of the VM is correct. If yes, the Web file in the corresponding directory is displayed to the requesting user.

 

Possible errors: cocould not reliably determine the server's fully qualified domain name

Modify/etc/apache2/httpd. conf. This file is empty. Add servername localhost.

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.