How Apache uses basic articles

Source: Internet
Author: User

Apache is the most commonly used Web server in the world. For Linux users, it's also the easiest Web server to use, and it's free. In fact, if you just want to use Apache to provide basic Web page services, Then you may not need to adjust any configuration at all. But, on the other hand, Apache is a very powerful program that can provide a lot of professional functionality, and you still have to know a little about its configuration in order to perform its function.
  
First, if you're using Apache on a non-Linux site, or if your site is heavily burdened (for example, more than 1000 simultaneous connections), then you usually have to recompile Apache, which we don't introduce here.
  
(1) Start to provide Web services
  
There are two ways to serve Apache, that is, by inetd or by independent execution of httpd. In general, we use the independent execution method. First you must install the Apache server. The usual Linux distributions will include the Apache RPM package, which can be installed with rpm-i. Then you have to test it correctly. Take an HTML file, name it index.html, and copy it to/home/httpd/ HTML directory, and then execute httpd as root, and then use browser on another machine to access the IP address of your machine, and you should be able to display its contents. If not, check your work and start again.
  
Apache defaults to the use of the page file is index.html, error output in/var/log/httpd/, if there is an abnormal problem, look inside the Error_log file.
  
Many times, you need to change the location of your Web files, or introduce some CGI services to your Web pages, so you have to modify the/etc/httpd/conf/srm.conf file. First, you will find the following paragraph:
  
Documentroot/home/httpd/html
  
This sentence shows that the page file that Apache uses is stored in/home/httpd/html, so if you want to change the way the Web is stored, you should modify it here.
  
The other corresponding paragraph is
  
DirectoryIndex index.html index.shtml index.cgi
  
It shows that if someone accesses your machine, the home page will be index.html or index under the path defined above. shtml,index.cgi. If your home page is another name, modify this sentence.
  
Another common option is to
  
scriptalias/cgi-bin//home/httpd/cgi-bin/
  
It defines that when using a CGI program, the directory referenced by the page is/cgi-bin/, and the actual path is/home/httpd/cgi-bin/
  
(2) using Apache to make Web Proxy
  
Proxy is the agent. Apache Web Proxy is a way to have the client server access www through Apache, so that the Apache server will receive requests from the client machine, then first go to the target site and store the content on the Apache server, And then submit it to the customer. If another client needs to access the same content later, Apache will get the content directly from the server's hard drive and submit it to the customer.
  
To use Apache proxy, you need to edit/etc/httpd/conf/httpd.conf, assuming your Apache machine address is 111.111.111.111, and the proxy port is 8080 (typically you should choose a value greater than 1024), and the paragraph you need to change has
  
Listen 111.111.111.111 8080 #打开8080端口
  
Proxyrequest on #启动Proxy服务

CACHEROOT/VAR/CACHE/HTTPD #缺省的Proxy Cache directory, must be writable directory
  
CacheSize #Cache的大小, the unit is KB, it's not harmless for you to set a larger bit, right?
  
Cachegcinterval #每隔多少小时自动清理cache, remove garbage that exceeds cache space
  
Cachemaxexpire #Cache的最大有效期, or the cache can be up to a few hours behind the times.
  
Cachedefaultexpire 4 #缺省的Cache有效期, Unit is hour
  
Proxyremote http://something.com http://otherproxy.com:8080/
  
#对于到http://something.com's access to automatically invoke another Web Proxy defined in otherproxy.com:8080,
  
#也可以用ProxyRemote FTP http://otherproxy.com:8080/
  
#定义一个专门对ftp的Proxy级联.
  
Noproxy. mydomain.com 111.111.111.0/24
  
#对于来自111.111.111.1-111.111.111.254 and the requests pointing to *.mydomain.com do not use proxies,
  
#这可以使cache只对外部网有效.
  
Next, you should set up your own internal users to use proxy, which requires modification of the/etc/httpd/conf/access.conf
  
Add the following paragraph:
  
#Proxy Access Restrictions
Order Allow,deny #顺序: Default prohibit
Allow 111.111.111.0/24 #允许111.111.111.0-111.111.111.254 use,

#/24 refers to the network mask is 24 1, that is, 255.255.255.0
#段落结束
  
Now, restart the httpd and set up your client, and set the proxy server to 111.111.111.111:8080.
  
(3) Virtual host
  
Apache Name Virtual host is a good feature, it can use an Apache machine, an IP to provide multiple pages, setting is very simple, you need to edit/etc/httpd/conf/httpd.conf, assuming that there are two names: A.domain.com and b.domain.com all point to 111.111.111.111 (note that the two overlapping names produced by CNAME can only be counted as a virtual host, you have to 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 #说明111.111.111.111 is a virtual host
  
#第一个虚拟主机
ServerName a.domain.com #虚拟主机名
documentroot/home/httpd/html/a.domain.com/#a. domain.com Address of the home page file
Errorlog/var/log/a.log #错误信息记录
ServerAdmin mastera@domain.com #管理员的邮件地址 (optional)

#段落结束
#第二个 ServerName b.domain.com
documentroot/home/httpd/html/b.domain.com/
Errlog/var/log/b.log
ServerAdmin masterb@domain.com


When the previous setting is complete, restart the httpd.
by the way, what if you want to configure a CGI script for each virtual user? Simply add a scriptalias paragraph to the

〈virtualhost〉 paragraph about this user, for example, this:

scriptalias/cgi-bin//home/httpd/html/ a.domain.com/cgi-bin/

So that a reference to the http://a.domian.com/cgi-bin/is automatically turned to/home/httpd/html/a.domain.com/cgi-bin/

. Of course, like DirectoryIndex can also put in, hehe.

(4) Other description

now has a program called Commanche, you can use the Web page to manage Apache, but I still like to modify the configuration file directly, there is a better deal with the problem, hehe. Another important issue with

is that if you allow others to use your server to publish Web pages, you must be careful that a very important paragraph in/etc/httpd/conf/httpd.conf is

User nobody br>
Group Nobody

defines that the system uses nobody permissions when httpd access, which avoids many security issues and should never be set to root!

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.