Configure the apache2 server

Source: Internet
Author: User

Install Apache in Ubuntu

Installation command: sudo apt-Get install apache2

After installation:

The generated startup and stop files are:/etc/init. d/apache2

Start: sudo apache2ctl-K start

Stop: sudo apache2ctl-K stop

Restart: sudo apache2ctl-K restart

The configuration file is saved in:/etc/apache2.

Note that the common Apache release configuration file is:

Httpd. conf

The main configuration file of the Ubuntu release version is:

Apache2.conf

The following file is referenced in apache2.conf:

# Configurations that contain dynamic modules:

Include/etc/apache2/mod-enabled/*. Load

Include/etc/apache2/mod-enabled/*. conf

# Include your own configurations:

Include/etc/apache2/httpd. conf

# Configurations that contain port listening:

Include/etc/apache2/ports. conf

# Contains a general configuration statement segment:

Include/etc/apache2/CONF. d/

# Configuration commands containing virtual hosts:

Include/etc/apache2/sites-enabled/

Modify httpd. conf

Add the following content:

Servername 127.0.0.1: 80


Ubuntu apache2 Configuration

1. apache2.conf is the main configuration file and the httpd. conf user configuration file.
2. The virtual directory is in httpd. conf.
<Virtualhost *>
DocumentRoot "path"
Servername
<Directory "path"> allow from all options + indexes </directory>
</Virtualhost>

3. The root setting (default main directory) is in/etc/apache2/sites-available/default
4. Restart command
sudo /etc/init.d/apache2 restartOr
CD/etc/init. d
Sudo apache2-K restart
Stop stop; start
5. log files are stored in/var/log/apache2/
<Virtualhost *: 80>
Servername www.kimoqi.com
DocumentRoot/home/vsftpd/kimoqi
</Virtualhost>
<Virtualhost *: 80>
Servername www.arwenedu.com
DocumentRoot/home/vsftpd/wangguan/webapps
</Virtualhost>
<Virtualhost *: 80>
Servername www.arwenedu.org.cn
DocumentRoot/home/vsftpd/wangguan/Chem
</Virtualhost>

VI/etc/httpd/CONF/httpd. conf

In Windows, there is usually only one configuration file for Apache, that is, httpd. conf. But after I installed apache2 with the apt-getinstallapache2 command on Ubuntu Linux, I found that its httpd. conf (located 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:

Reference

# 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:

Reference

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 you create a link to a VM configuration file under sites-enabled, it is enabled. To disable a VM, you only need to delete the link, you 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 installphp5, The php5.load, php5.conf, and links to the 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. You can also 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 virtualhost 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.

  1. <Virtualhost *>
  2. Servername Domain Name
  3. DocumentRoot treats the public in the rails project as the root directory
  4. <Directory public root directory>
  5. Options execcgi followsymlinks
  6. AllowOverride all
  7. Allow from all
  8. Order allow, deny
  9. </Directory>
  10. Errorlog/var/log/apache2/error-Domain Name. Log
  11. </Virtualhost>

For further configuration and use, you can refer to the Apache manual.


Description of the Apache configuration file httpd. conf

DocumentRoot "/var/www/html" --- Apache default server home directory


Directoryindex index.html index.htm index. php index.html. var --- default document. Multiple files are separated by spaces.

Listen 192.168.1.1: 80 sets the listening IP address to 192.168.1.1 and port to 80.

Listen 192.168.1.2: 8080 set the listening IP address to 192.168.1.2 and port to 8080.

Serverroot "/etc/httpd" sets the path relative to the root directory, usually refers to the place where the configuration files and log files are stored. The default value is/etc/httpd, which generally includes conf and logs subdirectories.

Errorlog logs/error_log setting error log Note: If the log file storage path does not start with "/", it means that the file is relative to the serverroot directory.

Customlog logs/access_log combined access log (combined indicates the log format and common format)

Serveradmin lindenstar@163.com set the network administrator's email-when the client server error, the server usually returns the error prompt page to the client, in order to facilitate the resolution of the error, this page usually has the Administrator's email address, you can use
Serveradmin statement to set the Administrator's email address

Servername www.iigoogle.com: 80 sets the server host name (if there is a domain name, you can enter the domain name, if there is no domain name, you can enter the Server IP address)

Adddefaultcharset gb2312 sets the default Character Set and defines the default character set that the server returns to the client (because the Western European UTF-8 is the Apache default Character Set, garbled characters occur when accessing a Web page with Chinese characters, in this case, you only need to change the character set to gb2312, and then restart the apache service)

Alias/down "/software/download" to create a virtual directory (create a virtual directory named down. Its physical path is/software/download)
Alias/ftp "/var/ftp" create a virtual directory (create a virtual directory named FTP with the corresponding physical path:/var/FTP)

<Directory "/var/www/html"> Set directory permissions (<directory "directory path"> statements for setting directory permissions for this write operation </directory>)
Options followsymlinks page: 116
AllowOverride none
</Directory>


Domain name-based VM
Namevirtualhost 220.123.55.99 --- use the namevirtualhost command to specify the IP address to respond to the VM request.
<Virtualhost www.iigoogle.com>
Servername www.iigoogle.com: 80
Serveradmin iigoogle@163.com
DocumentRoot/www/docs/iigoogle
Directoryindex index. jsp
Errorlog logs/www/iigoogle/error_log
Customlog logs/www/iigoogle/access_log common
</Virtualhost>
Another method
Namevirtualhost 220.123.55.99: 80
<Virtualhost www.iigoogle.com: 80>
Servername www.iigoogle.com
Serveradmin iigoogle@163.com
DocumentRoot/www/docs/iigoogle.com
Errorlog logs/www/iigoogle/error_log
Customlog logs/www/iigoogle/access_log common
</Virtualhost>

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.