Apache advanced settings guide for typical WEB servers

Source: Internet
Author: User
Article Title: Apache advanced settings guide for typical WEB servers. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
At present, there are many WWW Server software and many can run in linux, including NCSA HTTPd Server, CERN HTTPd Server, pache, Netscape Fast Track Server, and Zeus Server. These software features: NCSA (National Super Computing Application Center of the University of Illinois) is the place where WWW Browser Mosaic was developed and where Netscape Anderson became famous; CERN (European Nuclear Research Center) is the origin of WWW. In 1989, Tim berneas-Li successfully developed the world's first Web server and client. The two WWW servers have complete functions and become the standards of similar software. In addition, they are all Freeware, so they were very popular when they were launched. In the past few years, NCSA and CERN were the most widely used WWW Server software in linux, but over the past one or two years, Apache has been the only one to show off and is called "The King of WWW Server ". Apache is included in the latest versions of Red Hat, Slackware, and OpenLinux.
  
Apache is developed on the basis of NCSA, so the configuration files of the two are very similar.
  
   I. Installation
Apache installation is very simple. It is best to install the Web Server when installing RedHat, so that even if you are not familiar with the compilation operation, you can easily set up the Server.
  
If you want To compile the source file in person, you are not a beginner. You are advised To go directly To the How-To document or other materials. Open the machine, enter the X-Window system, start Netscape Navigator, and enter the IP address of the Local Machine. If the welcome page "It worked" appears, the server program works properly. You can perform the next step. In different versions, the default working root directory of the server is different. Red Hat uses/etc/httpd by default. The configuration file is in the/etc/httpd/conf directory, and the page file is in the/home/httpd directory.
  
   2. Set the httpd. conf, srm. conf, and access. conf files.
After Apache is installed successfully, there are four files in the conf sub-Directory: httpd. conf, srm. conf, access. conf and magic (Note: In the www-howto document, the fourth file is mime. types, but in actual installation, It is a magic file in the conf sub-directory ). Httpd. conf is the main file in the Apache configuration file. When the httpd program starts, it will first read httpd. conf. Srm. conf is a data configuration file. It mainly sets the directory for WWW Server to read files, the screen for directory indexing, And the directory for CGI execution. Access. conf is responsible for basic file read control and limits the functions that can be performed by the Directory and permission settings for accessing the directory.
  
The following describes the three data settings files.
  
Httpd. conf file
  
TransferLog:
  
If you want to know which page on your website is most popular with visitors and how many people visit your website within a period of time, you can set a counter, however, the counters on each page are too cumbersome and the results are not reliable. The best way is to view the corresponding log file. The TransferLog command is to specify that when the browser requires the server to transfer the file to the set file, you can view which users have viewed the HTML file based on the file. Some programs can be used to analyze the data of this file to obtain useful data for monitoring. The default access log file is logs/access_log.
  
ErrorLog:
  
This command specifies the file to which the error message is stored when a problem occurs during the operation of the WWW Server. The default value is logs/error_log.
  
VirtualHost:
  
This command is used to set up a virtual host, that is, using a host to execute WWW Server with multiple domain names. Detailed command usage will be explained in the third part.
  
Srm. conf
  
DocumentRoot:
  
Specifies the root directory for WWW Server to store html files. The WWW Server reads html files from the hard disk and sends them to the browser. Instead of reading files from any directory, it reads files from a specific directory, the specified directory is specified by the DocumentRoot command. The default directory in red hat5.2 is/home/httpd/html.
  
If you access http://www.swm.com.cn/netlife/index.html, then WWW server does not read index.html from the netlife.html file in the system's root directory, but reads the index.html file from the/home/httpd/html/netlifefile.
UserDir:
  
If you want to open space for some users on the WWW Server and put it on the personal homepage, it is best not to put all html files in the DocumentRoot directory, use the UserDir command to place the pages of each person in their home directory. The default directory is public_html.
  
If the directory set by UserDir is public_html, and Username is yan, and the home directory of the user is/home/yan, then you access http://www.swm.com.cn /~ The intr.html file viewed at yan/intr.html is stored in/home/yan/public_html instead of/home/httpd/html.
  
Access. conf
  
If some directories only allow access by some people, or only allow CGI programs under a specific directory, modify access. conf.
  
There are two access Control Methods for Apache: one is "overall access control", only through access. conf to control the file settings, to limit the functions that can be performed by the Directory and the permission settings for accessing the directory. The second is "Access Control for specific directories". Create an access setting file in a specific directory. The file name is determined by AcessFileName in srm. conf. The default value is. htaccess. For example, if files in some directories are only accessible to some people, you can create files in these directories. the htaccess file is automatically read when the WWW Server reads the directory. htaccess to determine whether to read and execute or require password verification. These two methods use almost the same commands and the same format.
  
Directory:
  
Description of the directory to be set, and then use commands to set the features and permissions of the directory.
  
Options:
  
Set the functions that the directory can perform. Options include None, All, ExecCGI, Des, Indexs, IncludesNoExec, FollowSymlink, and SymlinksOwnerMatch. If you want a directory to execute CGI programs, add the ExecCGI option to the Options command.
  
Require:
  
Set the Users and Group that can be accessed to the specified directory in a specified way. After the command is executed, when reading the data in this directory, the system requires that the Username and Password be entered.
  
TIPS: Do not restart the server to make the settings take effect as you do in Windows. Remember, in linux, one of the advantages of using linux is that you do not need to see the blue screen when Windows 98 crashes and do not have to make a little modification to the configuration file, so you will be bored and often restart the machine. Many people visit your WWW server at any time. Restarting the server frequently will drive your guests away. You must learn not to restart the machine, but to restart a program that is being executed (Process, strictly called Process and job ). You can run the kill command to restart the program. For more information about how to use kill, see the relevant documentation.
  
Run the ps command to view the httpd pid and kill it to restart httpd. The command is as follows:
  
Linux> ps-x
Linux> kill-HUP 13668
  
(13668 is the pid Number of httpd. In actual use, different values are also different)
  
In this way, you can restart httpd to make the modified configuration file take effect. After reading a bunch of commands above, isn't it annoying? In fact, it doesn't matter if you don't know these commands, and you can work normally with the default settings of the system.
  
   3. Virtual Host settings
As a system administrator, if you only have one IP address but have several domain names and want to access each domain name to see different content, what should you do? I don't always want to add a server to each domain name. This requires the use of Virtual Host technology. Fortunately, Apache supports this function. There are two methods for a VM: IP-Based and Name-based ). IP-Based refers to a domain Name corresponding to an IP address, while Name-based refers to multiple domain names corresponding to one IP address.
  
The VM settings are not complex. You only need to add the corresponding commands to the httpd. conf file.
  
The following is an example of httpd. conf for a Name-based (Domain Name-based) virtual host (Editor's note: for space reasons, we only provide the relevant sections. For the full text, see www.swm.com.cn ). The IP address is 192.168.188.20. The two domain names are long.com.cn and com.cn.
  
Httpd. conf:
  
NameVirtualHost 192.168.188.20
  
ServerAdmin webmaster@long.com
ServerName www.long.com
DocumentRoot/home/httpd/long/html
  
ErrorLog logs/error_log
TransferLog logs/access_log
  
ServerAdmin webmaster@short.com
ServerName www.domain.com
DocumentRoot/home/httpd/short/html
ErrorLog logs/logs .com-error_log
TransferLog logs/pai.com-access_log
  
The NameVirtualHost command specifies the IP address on which the VM is set.
  
Perform specific settings for each host in the VirtualHost command.
  
The ServerAdmin command sets that when the WWW Server fails to run, it will send the e-mail set by ServerAdmin to the browser, so that the user can use this e-mail to contact the system administrator.
  
The ServerName command is used to set the Domain Name of the WWW Server.
  
   4. Set the personal homepage space and user's homepage
I often see that some websites provide personal homepages, and they are very excited. In fact, you can also open up the space on your machine to others. This is easy to implement. As long as you follow the prompts below to modify your WWW server configuration file.
  
To open the personal homepage space for users, you must first determine the storage directory of the user homepage, and second, open the read permission for the user homepage directory.
  
Method 1
  
You can create an account for user chen as root. The system will automatically allocate a space/home/user to the account chen, and then create a public_html subdirectory under the/home/chen directory, sub-directory attributes must be set to other readable and executable.
  
Then modify access. conf. Add the following section at the end of the file:
  
AllowOverride None
Order allow, deny
Allow from all
  
Then, run httpd again, the user can through the http://www.swm.com.cn /~ Chen/access chen's personal homepage.
The advantage of this method is convenience, but the disadvantage is the poor security.
  
Method 2
  
Another method is to create a directory named chen under the/home/httpd directory. Modify UserDir in srm. conf to/home/httpd/*/html, and run httpd again.
Related Article

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.