Install and configure Apache2.4 In Ubuntu (including the virtual host configuration method)

Source: Internet
Author: User
Tags fully qualified domain name

Install and configure Apache2.4 In Ubuntu (including the virtual host configuration method)
Install the apache installation command in Ubuntu14.14: sudo apt-get install apache2 after installation is complete: The generated startup and stop files are:/etc/init. d/apache2 start: sudo apache2ctl-k start stop: sudo apache2ctl-k stop restart: The sudo apache2ctl-k restart configuration file is saved in:/etc/apache2, the common apache release configuration file is httpd. the main configuration file of the conf Ubuntu release version is: apache2.conf references the following file in apache2.conf: # Include/etc/apache2/mod-enabled /*. load Include/etc/apache2/mod-enabled /*. conf # contains your own configurations: Include/etc/apache2/httpd. conf # configuration containing port listening: Include/etc/apache2/ports. conf # contains the general configuration statement segment: Include/etc/apache2/conf. d/# Include the VM configuration command: Include/etc/apache2/sites-enabled/modify httpd. add the following content to the conf file: ServerName 127.0.0.1: 80 ubuntu apache2 configuration 1. apache2.conf is the main configuration file, httpd. conf user configuration file 2. the virtual directory is in httpd. <VirtualHost *> DocumentRoot "path" ServerName <Directory "path"> allow from all Options + Indexes </Directory> </VirtualHost> 3. root settings (default main directory) in/etc/apache2/sites-available/default4. restart the command sudo/etc/init. d/apache2 restart or cd/etc/init. dsudo apache2-k restart stop; start 5. log files are stored in/var/log/apache2/<VirtualHost *: 80> ServerName www. kimoqi. comDocumentRoot/home/vsftpd/kimoqi </VirtualHost> <VirtualHost *: 80> ServerName www. arwenedu. comDocumentRoot/home/vsftpd/wangguan/webapps </VirtualHost> <VirtualHost *: 80> Serv ErName www.arwenedu.org. cnDocumentRoot/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. 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. In apache2.conf, you can find these Include rows: Reference # Include module configuration: Include/etc/apache2/mod-enabled /*. loadInclude/etc/apache2/mod-enabled /*. conf # Include all the user invocations: Include/etc/apache2/httpd. conf # Include ports listingInclude/etc/apache2/ports. conf ...... # Include generic snippets of statementsInclude/etc/apache2/conf. d/# Include the virtual host configurations: Include/etc/apache2/sites-enabled/with comments, you can clearly see the general role 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 @ localhostDocumentRoot/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 a link is established under sites-enabled to a virtual host configuration file, it is enabled. To disable a virtual host, you only need to delete the corresponding 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 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> for further configuration and use, you can refer to the APACHE manual and the Apache configuration file httpd. conf description DocumentRoot "/var/www/html" --- default directory of Apache Server Directory DirectoryIndex index.html index.htm index. php index.html. var --- default document, multiple Separate Listen 192.168.1.1: 80 with spaces. Set 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 the port to 8080 ServerRoot "/etc/httpd" to set the path relative to the root directory, usually the location where the configuration files and log files are stored. The default value is:/etc/httpd generally includes conf and ErrorLog logs/error_log in the logs subdirectory. Note: If the log file storage path does not start, this file is relative to the ServerRoot directory CustomLog logs/access_log combined access log (combined indicates the log format, and common format) serverAdmin [email protected] sets the network administrator's Email. When an error occurs on the client server, the server usually returns an error prompt page to the client, this webpage usually has the Administrator's Email address. You can use the ServerAdmin statement to set the Administrator's EMail address ServerName www.iigoogle.com: 80 to set the server host name (if there is a domain name, you can enter the domain name, if there is no domain name, enter the Server IP address.) AddDefaultChar Set GB2312 sets the default character set, which defines the default Character set returned by the server to the client (because the Western Europe UTF-8 is the Apache default Character set, garbled characters occur when accessing a Web page with Chinese characters, at this time, 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, and its corresponding 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 </Directory>) Options FollowSymLinks page: 116 AllowOverride None </Directory> domain name-based Virtual Host NameVirtualHost 220.123.55.99 --- use the NameVirtualHost command to specify which IP address is used to respond to requests to the virtual host <VirtualHost www.iigoogle.com> ServerName www.iigoogle.com: 80 ServerAdmin [email protected] DocumentRoot/www/docs/iigoogle DirectoryIndex index. jsp ErrorLog logs/www/iigoogle/error_log CustomLog logs/www/iigoogle/access_log common </VirtualHost> another way to write NameVirtualHost runtime: 80 <VirtualHost www.iigoogle.com: 80> Serv ErName protected ServerAdmin [email protected] DocumentRoot/www/docs/iigoogle.com ErrorLog logs/www/iigoogle/error_log CustomLog logs/www/iigoogle/access_log common </VirtualHost> in Windows, apache usually has only one configuration file, 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 lines 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 role 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 a link is established under sites-enabled to a virtual host configuration file, it is enabled. To disable a virtual host, you only need to delete the corresponding 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 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 ). The configuration format is in Apache2. 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 ServerName www after ServerName. jianzhan. love # If you want to obtain the same website name for multiple websites, you can 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. If you have any questions, contact the website administrator. ServerAdmin [email protected] # 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 Allo W 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 to <VirtualHost IP Address [: port]>... </VirtualHost> enable the previously configured virtual host, which is only "valid". If it works well, you must put it in/etc/apache2/sites-e. Under the nabled 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 syntax, to restart the web service, be cautious. Check the syntax sudo apache2ctl configtest before restarting the service. Restart Apache sudo/etc/init. d/apache2-k restart or sudo service apache2 restart. The main setting of the effect is completed. It's quite 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. jianzhan. the effect of love is to enter www in the browser. jianzhan. love will directly go to the IP address 192.168.1.22 server to receive the request, check whether there is a qualified virtual host domain name, if yes, the WEB files in the corresponding directory will be displayed to the requesting user. the possible error cocould not reliably determine the server's fully qualified domain name will be changed to/etc/apache2/httpd. conf 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.