Article title: Apache usage basics. 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.
Apache is the most frequently used Web server in the world. for Linux users, it is also the easiest Web server to use, and it is free of charge. in fact, if you only want to use Apache to provide basic Web page services, you may not need to adjust any configuration at all. however, on the other hand, Apache is a very powerful program that provides many professional functions. to make full use of its functions, you still need to know a little about its configuration.
First, if you use Apache on a non-Linux website, or your website is heavily burdened (for example, more than 1000 simultaneous connections), you usually have to recompile Apache, we will not discuss this issue here.
(1) starting to provide Web services
Apache services can be implemented in either inetd or httpd independently. in general, we use an independent execution method. first, you must install the Apache server. generally, the Linux release contains the apache rpm Package. you can use rpm-I to install it. then, you need to test your website. you can use an html file named index.html, copy it to the/home/httpd/html directory, and execute httpd as the root user, next, use Browser to access the IP address of your machine on another machine, and the content should be displayed. if not, check your job and try again.
The page file used by apachelogs is index.html, and the error output is/var/log/httpd/. if the problem persists, check the error_log file.
In many cases, you need to change the storage location of web files or introduce some cgi services to web pages. Therefore, you must modify/etc/httpd/conf/srm. conf file. first, you will find the following paragraph:
DocumentRoot/home/httpd/html
This sentence indicates that the page files used by Apache are stored in/home/httpd/html, so you should modify the web storage path here.
Another corresponding section is
DirectoryIndex index.html index.shtml index. cgi
If someone else builds your machine, the first page will be index.html or index. shtml, index. cgi. If your website homepage is named another one, modify this sentence.
Another common option is
ScriptAlias/cgi-bin // home/httpd/cgi-bin/
It defines that when using CGI programs, the directory referenced by the page is/cgi-bin/, and the actual storage path is/home/httpd/cgi-bin/
(2) use apache for Web Proxy
Proxy is the Proxy. apache web proxy allows the client server to access WWW through Apache. in this way, the Apache server will receive requests from the client machine and then first obtain the content from the target site, store the content on the Apache server and submit it to the customer. in the future, if another client needs to access the same content, Apache will directly obtain the content from the server's hard disk and submit it to the customer.
To use Apache Proxy, edit/etc/httpd/conf/httpd. conf. assume that your Apache machine address is 111.111.111.111 and the proxy port is 8080 (usually a value greater than 1024 should be selected ).
Listen 111.111.111.111 8080 # open port 8080
ProxyRequest On # Start the Proxy service
CacheRoot/var/cache/httpd # default Proxy Cache directory, which must be writable
CacheSize 2000 # Cache size, unit: KB. setting a large value is harmless to you, right?
CacheGcInterval 48 # automatically clears the cache every few hours and deletes the garbage that exceeds the cache space
CacheMaxExpire 24 # Maximum Cache validity period, or the maximum number of hours the Cache can lag behind
CacheDefaultExpire 4 # default Cache validity period, in hours
# For access to the http://something.com, automatically call another Web Proxy defined in otherproxy.com: 8080,
# You can also use ProxyRemote ftp http://otherproxy.com: 8080/
# Define a Proxy Cascade dedicated to ftp.
NoProxy .mydomain.com 111.111.111.0/24
# Do not use a proxy for requests from 111.111.111.111.1-111.111.254 that point to * .mydomain.com,
# This can make the cache only valid for the external network.
Next, you should set that only your internal users can use the Proxy, which requires modifying/etc/httpd/conf/access. conf
Add the following section:
# Proxy access restrictions
Order allow, deny # order: Disabled by default
Allow 111.111.111.0/24 # allow 111.111.111.0-111.111.111.254,
#/24 indicates that the network mask is 24 to 1, that is, 255.255.255.0
# End of a paragraph
Now, restart httpd, set your client, and set the proxy server to 111.111.111.111: 8080.
(3) virtual host
Apache name VM is a good function. it can use an Apache machine and an IP address to provide multiple pages. The setting is very simple, you need to edit/etc/httpd/conf/httpd. conf. assume that both a.domain.com and B .domain.com point to 111.111.111.111, you must define two records in the domain name), then you can add the following paragraph:
Listen 111.111.111.111 80
NameVirtualHost 111.111.111.111: 80 # Description 111.111.111.111 is a virtual host
# First VM
ServerName a.domain.com # virtual host name
DocumentRoot/home/httpd/html/a.domain.com/# address for storing the home page file of a.domain.com
Errorlog/var/log/a. log # Error message record
ServerAdmin mastera@domain.com # administrator email address (optional)
# End of a paragraph
# ServerName B .domain.com
DocumentRoot/home/httpd/html/B .domain.com/
Errlog/var/log/B. log
ServerAdmin masterb@domain.com
Restart httpd after setting.
By the way, what if you want to configure CGI scripts for each virtual user? It's easy.
Add the ScriptAlias section to the VirtualHost section, for example:
. Of course, such as DirectoryIndex can also be put in.
(4) other instructions
Now there is a program named commanche, which can be managed by Apache on the web page. However, I still like to directly modify the configuration file. it is better to solve problems.
Another important issue is that if you allow others to use your server to publish web pages, you must be careful,/etc/httpd/conf/httpd. A very important section in conf is:
User nobody
Group nobody
It defines that the system uses the nobody permission for httpd access, which can avoid many security issues and never set it as root!
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