Linux Apache Configuration

Source: Internet
Author: User
Tags http authentication ftp protocol password protection

This document contributed by ybfq01230 PDF documents may not be in a WAP-side browsing experience. It is recommended that you choose TXT First, or download the source file to your native view. Apache Ginger Yingjie Apache Web Service, also known as Global Information Network www (World Wide Web) service, is one of the most popular services on the Internet. Web Service is an interactive graphical interface of the Internet service, with powerful information connectivity, the information through the Internet to every corner of the world! The Web server usually uses HTTP communication protocol for network communication, the user sends an HTTP request, the request is sent to the server (usually 80 port), the server responds to the corresponding page according to the user's request, send this information back to the client, after the client receives the information, on the display to the browser, The user can browse to the requested page content. APACHE current WWW server is mainly divided into two major camps--unixlike above the Apach with Windows above IIS. Apache is the free software developed by Apache, which is also the most widely used server software in the world, according to statistics, more than 65% of sites use Apache as its page server, and more than all other Web servers combined. IIS is another widely used Web server with about 15% of web sites. In terms of cost-effective, of course, Linux above the Apache best! At present, many dynamic websites are built with linux+apache+mysql+php, referred to as LAMP. Apache Apache features: Can run almost on all computer platforms support the latest http/1.1 protocol support for the virtual host HTTP authentication Apache Apache Architecture: Apache using pre-derivation technology, the main process is httpd, it will derive the A multi-child process to monitor a client's connection request, rather than generating a new process whenever a new input request is available, which can increase the user's connection speed and httpd the master process kills some child processes when the child process exceeds a front value. APACHE HTTP (Hypertext Transfer Protocol): Hypertext Transfer Protocol, is the current WWW transmission data of the mainstream protocol! Web pages on the site, you need to conform to hypertext Markup Language (HTML) syntax! URL: Uniform Resource Locator Format: protocol://destination host address [:p ort]/directory Resource A URL is a pointer to some data on the web, it can be a Web file, or an e-mail address. such as: http://www.163.com/index.html, HTTP is the protocol part, Www.163.com is the host part, index.html is the file part. APACHE protocol: HTTP, FTP, news, and more! HTTP protocol is the use of the host HTTP port (generally, the FTP protocol is the use of the host FTP port (typically 21), we use 80 and 21 is the service provided by the host! Even with HTTP and FTP connected to the same computer, the information obtained is not necessarily the same, because the service is different! One is the HTTP one is how the FTP will be the same. So how is the data of WWW transmitted? APACHE When we enter the URL in the browser URL bar: Client side through DNS resolution to get the IP of the WWW host, will send a packet, the HTTP protocol to join the WWW host, notify the WWW host to get data by HTTP method; www host received After the packet, according to the client side of the request, provide relevant information to respond, in most cases, the HTTP protocol to use the HTML syntax of the Web page data to the client browser; Finally, the client browser will parse the HTML syntax and display the content of the Web page. Apache Apache three ways of working: 1. Pre-derived 2. Worker 3. Standalone subprocess Apache currently has a 2.0.X version, can go to the official website www.apache.org download Apache software currently the highest version of Apache installation: #tar JXVF httpd-2.0.54.tar.bz2–c/ USR/LOCAL/SRC #cd/usr/local/src/httpd-2.0.54: Enter the extracted directory #./configure--enable-mods-shared=all: Compile, the parameter meaning is to install all the modules # Make: Compile the source code into an executable binary #make install: Put the compiled binaries into the appropriate places, such as/bin,/sbin Apache Apache will be installed by default in the/usr/local/apache2 directory Execute program path:/usr/local/apache2/bin Profile path:/usr/local/apache2/conf/httpd. conf Apache control file path/usr/local/apache2/bin/apachectl start or stop HTTP service:/usr/local/apache2/bin/apachectl start|stop| Restart home file path:/usr/local/apache2/htdocs Apache Apache command: Divided into core instructions, additional instructions, container instruction core directive: Global environment settings, ports and other information additional directives: instructions within the container directive, Each module is configured with container directives on the container: it can be applied only within the scope of the contained container definition, including:,, for example: Order Allow,deny allow from all//all hosts can access the above directory deny from 192.168.1//Not Allow this segment of the host to access the above directory Apache httpd.conf is the Apache configuration File core Directive main field meaning: Serverroot:apache software root directory! That is the installation path, there are many directories below the path is relative to this path! Listen 80: Server listening port, if you want to change the port of WWW, can be modified here, for example 8080, after the client if want to access this web page need to enter the URL is http://Host name/ip:8080 DocumentRoot "/usr/ Local/apache2/htdocs ": Sets the root document path, which is where the default Web page files are stored APACHE userdir public_html: Defines the home page root directory for the user home directory example: My home directory is/home/test, Then the root directory of the test home page is/home/test/public_html directoryindex index.html: Define the default home page when you enter http://192.168.0.66, Apache will Will search the directory under the file name (that is, set the default display of the Web page file), want to display the name of the Web page file, here to define what name, such as Index.html accessfilename. htaccess: Specifies the name of the protected directory profile APACHE Options follwsymlinks: Allow symbolic links to follow, access files not in this directory-format: Ln–s sfile (source file) test (target file) Options Indexes:If you don't see a list of files in the same directory as the default home page when you don't have a default home page, that is, if you can't find a index.html or other custom home page under the home directory or a custom directory, the file name is displayed in the entire directory! It's dangerous! So try not to include the Indexes item in the home directory! AllowOverride None/all: Disable/Allow reading of. htaccess files. The default is None, if you want to start the Web Authentication feature, set to all. APACHE additional Directive main field meaning: Order Allow,deny: Set permissions, some IP is not accessible, set a check order, Allow,deny in the middle is "," separated-if you want to allow most, reject a small part, can be set to: Order allow,d Eny allows from the all deny from 192.168.1.100 deny from www.haha.com--if you want to reject most, allow small portions, can be set to: Order Deny,allow deny from all AL Low from 192.168.1.100 allows from www.haha.com APACHE KeepAlive Off: Does not use the Keep-connect feature, where a client requests a connection to respond to only one file at a time. It is recommended that you set the value of this parameter to on, which allows you to use the Keep-connected feature. Maxkeepaliverequests 100: Defines the maximum number of requests for HTTP requests that can be made per connection in a persistent connection, that is, the maximum allowed connections! No limit can be set to 0 (0 is unrestricted). KeepAliveTimeout 15: The next request of the same connected Client is not sent within 15 seconds, the connection is considered broken, that is, if the server completes a connection, but the client has not requested the connection again after the connection is completed, the server automatically disconnects the connection after a few seconds. Apache Minspareservers 5: Minimum number of idle child processes Maxspareservers 20: Maximum number of idle child processes Apache typically uses the Create child process to respond to a request, and if each connection creates a child process, the Web The server's response can become very slow. As a result, the minspareservers and maxspareservers can be used to define the minimum number of empty sub-processes that Apache starts each time it launches by Minspareservers. So you can get rid ofThe system is too slow to respond to problems. However, there is no setting for the highest child process. Otherwise it will take up a lot of CPU and system resources and will eventually drag the system down. Startservers 8: Number of child processes started to be built APACHE Timeout 300: If the client has not requested the server for more than a few seconds, the server will automatically disconnect the connection (wire break processing)! MaxClients 150: Maximum client connections, defines the maximum number of clients allowed to connect to the Web server at the same time (concurrent), the default is 150, you can set a small, because the settings are too large and consuming system resources, too small to let a lot of people to connect! Set up a profile in the user's home directory, such as: Cd/home/test #mkdir public_html #chmod 755 public_html #chmod 755/home/test in public_html directory index.ht ML file to enter the test user's profile to enter in the IE URL: http//Your site name or ip/~test/to create a personal homepage How to need to add a Caterpillar symbol "~" It! Really annoying, can only use: HTTP//Your site name/test of course no problem! #vi/usr/local/apache2/conf/httpd.conf Add Alias/test "/home/test/public_html" #/usr/local/apache2/bin/apachectl Restart try it again! commands for accessing Web pages under text: #lynx www.163.com password protected directory settings when accessing certain resources of some websites, the browser pops up a dialog box that asks for a user name and password to gain access to the resource. This is a technology of user authentication. User authentication is the first line of defense to protect network system resources. The basic user authentication technology is "user name + password" under the HTPASSWD features Apache to implement text files to store user passwords. Password protected directory settings The basic idea of this authentication method is that Apache starts the authentication function, that is, to enable the allowoverride function, you can set up a file named. htaccess in the directory where you need to restrict access, specify the Authentication configuration command, Then Apache will look for the. htaccess file in each directory. When the user first accesses the directory's files, the browser displays a dialog box asking for a user name and password to confirm the user's identity. If you are a legitimate user, display theThe content of the page visited, and then each page of the directory, the browser automatically sends out the user name and password, no longer input, until the browser is closed. Password protected directory settings #mkdir –p/home/test/public_html/private: Establish the directory you want to protect private #vi index.html: Create a Web page file in this directory #cd/home/test/public_ Html/private #htpasswd –c. HTPASSWD Test: Add an Account-C: When the following. htpasswd This password file does not exist, set up the second account without the-C option example: 1. Create a new file and create a test ID htpasswd-c. htpasswd Test 2. password file already exists, to add user account htpasswd. htpasswd qqq-m: Modify the Password protection directory settings for users #cd/home/test/public_html/p Rivate #vi. htaccess, the file contents are as follows: AuthName "private passwd"//interpretation of the encrypted directory, the prompt character shown above the window AuthType Basic//Authentication encoding method AuthUserFile/ HOME/TEST/PUBLIC_HTML/PRIVATE/.HTPASSWD//password file storage Place, must be absolute path Require valid-user//Allow the user in the htpasswd file to access the Web directory password protection directory settings In profile httpd.conf The authentication feature is added at last: allowoverride All restarts the Apache server in the URL input http://IP/test/private/exercise to make a profile for the user, only haha users can access the home page. Virtual Host virtual host refers to the implementation of multiple Web sites on the same server (for example: Www.163.com and thiz.linux.com simultaneously running on a single host), for small businesses do not need a dedicated Web server to build their own web site virtual host is divided into:- IP-based virtual host-name-based virtual host virtual host IP-based virtual host: Each virtual host has its own IP address based on the name of the virtual host: each virtual host IP address is the same, host name different virtual host directive belongs to the container instruction IP-based virtual host IP-basedThe virtual host must have a different IP address. You can use a physical network link to achieve this demand, or use a network adapter to bind multiple IP addresses (virtual network card), that is, to configure an IP-based virtual host requires a multi-IP address of the server, and then configure the DNS server, to each IP address with a different domain name. All configuration directives for a virtual host are included in the segment, one for each virtual host. IP-based virtual host configuration process: 1, configure the IP address 2, modify the master configuration file configuration Virtual Host 3, set up the Virtual host Web page file and directory 4, start the HTTPD service IP-based virtual host temporarily increase the IP address #ifconfig eth0:0 192.168.1.2 permanently add IP address #cd/etc/sysconfig/network-scripts #cp ifcfg-eth0 ifcfg-eth0:0 #vi ifcfg-eth0:0 #service Network Res Tart the IP-based virtual host to edit the httpd.conf file, add the following: ServerName www.163.com documentroot/www/163 ServerName www.126.com documentroot/ www/126, ServerName: Server name documentroot: Virtual host Web root IP-based virtual host set up the corresponding Web page file #mkdir –p/www/163 #mkdri –p/www/126 in 163 and 126 respectively built Web file index.html IP-based virtual host Note: www.163.com and www.126.com must be parsed in DNS also write the corresponding relationship between the native IP and hostname to the/etc/hosts table, or Apache may not start normally Do not forget to specify the DNS server's IP name-based virtual host browser and server communication when the client tests, the server can track which host name is requested by the browser. As a result, you can use this new feature to set up a virtual host in an easier way. This method does not require an additional IP address, but requires a new version of browser support. This approach has become a standard way to build virtual hosts. To establish a non-IP-based virtual host, multiple domain names are not limited because each domain name corresponds to a virtual host to serve, so you need to change the configuration of the DNS server. Name-based virtual host when Apache encounters Namevirtuaho during read httpd.confSt instruction, it establishes a virtual host table for the specified IP address. When Apache parses httpd.conf, each time it encounters an instruction, the IP address specified by the instruction is added to the virtual host's list of virtual hosts for that IP address, which is the same as the IP address previously assigned to the virtual host. Name-based virtual host when the client finds a virtual host and its servername instruction matches the host header of the input request, Apache uses the configuration in the virtual host container to respond to the request, simply by pointing to the same IP address with multiple names. Name-based virtual host configuration name-based virtual host, modify httpd.conf namevirtualhost 192.168.2.1 ServerName www.qq.com documentroot/www/qq ServerName www.yahoo.com Documentroot/www/yahoo Exercise 1, configure the name-based virtual host www.google.com www.baidu.com 2, configure the IP-based virtual host www.sohu.com Www.sina.com

Linux Apache configuration

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.