Apache Website Services

Source: Internet
Author: User
Tags install perl

First, Apache Introduction
    • "Apache http Server" Open source software project distinguished representative, using standard HTTP network protocol to provide web browsing services, can run on a variety of operating system platforms; using the standard B/S architecture
    • Apache is the software that is formed after the integration and refinement of several Web server programs, which is named "A patchy server", which means "server program formed after modifying (patching) code based on the original Web service program"
    • 1995 release of version 1.0, after the "Apache Group" responsible for the management and maintenance of the project; 1999 Apache Foundation (Apache Software foundation,asf)
    • As one of the famous software projects of ASF, the official name is "httpd"
Second, Apache features
    • Open Source: Anyone can freely use, fully embodies the spirit of open source software
    • Cross-platform applications: can be run on most hardware and software platforms, thanks to the open source code of Apache
    • Support for various web programming languages: Perl, PHP, Python, Java, ASP, etc.
    • Modular design: The Apache function is divided into various modules, what functions need to directly load the corresponding modules, and support commercial self-development module
    • Run stable: can be used to build Web sites with heavy load traffic
    • Good security: The maintenance team provides patches for discovered vulnerabilities in a timely manner
Third, Apache version
    • 1.X: Up to 1.3, this version inherits the excellent features and configuration management style since the Apache Server version 1.0, with good compatibility, stability; currently stopped maintenance
    • 2.x:apache joins many new features, new configuration syntax and management style
Iv. httpd Error Codes
  • 100 (continuation)-The requestor shall continue to make the request. The server returns this code to indicate that the first part of the request was received and is waiting for the remainder
  • 101 (Switching protocol)-the requestor has asked the server to switch protocols, the server has confirmed and is ready to switch
  • 200 (Success)-The server has successfully processed the request. Typically, this indicates that the server provided the requested Web page. If this status code is displayed for your robots.txt file, it means that Googlebot has successfully retrieved the file
  • 201 (created)-the request was successful and the server created a new resource
  • 202 (accepted)-the server has accepted the request but has not yet processed
  • 203 (non-authoritative information)-The server has successfully processed the request, but the information returned may be from another source
  • 204 (no content)-The server successfully processed the request, but did not return any content
  • 205 (reset content)-The server successfully processed the request, but did not return any content. Unlike the 204 response, this response requires the requestor to reset the document view (for example, to clear the form contents to enter new content)
  • 206 (partial)-The server successfully processed a partial GET request
  • 300 (multiple options)-the server can perform a variety of actions for the request. The server can select an action based on the requestor (user agent) or provide a list of actions for the requestor to select
  • 301 (permanent move)-the requested page has been permanently moved to a new location. When the server returns this response (a response to a GET or HEAD request), the requestor is automatically forwarded to the new location. You should use this code to tell Googlebot that a webpage or website has been permanently moved to a new location
  • 302 (temporary Move)-the server is currently responding to a request from a Web page in a different location, but the requestor should continue to use the original location to respond to subsequent requests. This code, similar to the 301 code that responds to the GET and HEAD requests, will automatically move the requestor to a different location, but you should not use this code to tell Googlebot that a Web page or site has moved because Googlebot will continue to crawl the original location and index it
  • 303 (See other locations)-The server returns this code when the requestor should use a separate GET request for the different locations to retrieve the response. For all requests except HEAD, the server automatically goes to a different location
  • 304 (unmodified)-The requested webpage has not been modified since the last request. When the server returns this response, the Web page content is not returned, and if the page has not changed since the requestor last requested it, you should configure the server to return this response (known as the If-modified-since HTTP header). The server can tell the search engine that the spider/bot has not changed since the last crawl, thus saving bandwidth and overhead
  • 305 (use proxy)-the requestor can only use the proxy to access the requested Web page. If the server returns this response, it also indicates that the requestor should use the proxy
  • 307 (Temporary redirect)-The server is currently responding to a request from a Web page in a different location, but the requestor should continue to use the original location to respond to subsequent requests. This code, similar to the 301 code that responds to the GET and HEAD requests, will automatically move the requestor to a different location, but you should not use this code to tell Googlebot that a page or site has moved because Googlebot will continue to crawl the original location and index it
  • 400 (Bad Request)-the server does not understand the syntax of the request
  • 401 (unauthorized)-Request authentication required. The server may return this response for the requested web page after login
  • 403 (Forbidden)-The server rejects the request. If you see this status code when Googlebot tries to crawl a valid webpage on your site (you can see this information on the Web crawl page under Google Webmaster Tools Diagnostics), your server or host may have denied Googlebot access
  • 404 (Not found)-the server could not find the requested webpage. For example, this code is often returned for pages that do not exist on the server, and if you do not have a robots.txt file on your site and you see this status code on the robots.txt page of the Google Webmaster Tools Diagnostic tab, this is the correct status code. However, if you have a robots.txt file and you see this status code, your robots.txt file may be named incorrectly or in the wrong location (the file should be in the top-level domain named robots.txt), or if you see this status code for Googlebot crawled URLs ( On the HTTP error page of the Diagnostics tab, it means that Googlebot follows a potentially invalid link to another page (an old link or an incorrectly entered link)
  • 405 (method Disabled)-disables the method specified in the request
  • 406 (not accepted)-unable to respond to the requested Web page using the requested content attribute
  • 407 (requires proxy authorization)-This status code is similar to 401 (unauthorized), but specifies that the requestor should authorize the use of the proxy. If the server returns this response, it also indicates that the requestor should use the proxy
  • 408 (Request timed out)-timeout occurs when the server waits for a request
  • 409 (conflict)-the server has a conflict when the request is completed. The server must include information about the conflict in the response. This code may be returned by the server in response to a PUT request that conflicts with the previous request, as well as a list of differences of two requests
  • 410 (Deleted)-The server returns this response if the requested resource has been permanently deleted. This code is similar to the 404 (not Found) code, but is sometimes used to replace the 404 code in cases where the resource existed before and now does not exist. If the resource has been permanently moved, you should use 301 to specify a new location for the resource
  • 411 (valid length required)-The server does not accept requests that do not contain a valid Content-Length header field
  • 412 (precondition not met)-one of the prerequisites that the server did not satisfy the requestor to set in the request
  • 413 (Request entity too Large)-the server cannot process the request because the request entity is too large to exceed the server's processing power
  • 414 (The requested URI is too long)-The requested URI (usually the URL) is too long for the server to process
  • 415 (Unsupported media type)-The requested format is not supported by the requested page
  • 416 (Request scope does not meet requirements)-if the page cannot provide the requested range, the server returns this status code
  • 417 (unmet expectations)-the server does not meet the requirements of the "expected" Request header field
  • 500 (server internal error)-The server encountered an error and could not complete the request
  • 501 (not implemented)-the server does not have the ability to complete the request. For example, this code may be returned when the server does not recognize the request method
  • 502 (Bad Gateway)-the server received an invalid response from the upstream server as a gateway or proxy
  • 503 (Service Unavailable)-the server is not currently available (due to overloading or downtime maintenance). Usually, it's just a temporary state.
  • 504 (Gateway Timeout)-The server acts as a gateway or proxy, but does not receive requests from the upstream server in a timely manner
  • 505 (HTTP version not supported)-the HTTP protocol version used in the request is not supported by the server
V. Deployment of HTTPD Services 1. Preparatory work
    • RPM-E httpd--nodeps//uninstall httpd installed using RPM mode
    • Sed-i '/hostname/d;ahostname=www.hiahia.com '/etc/sysconfig/network//Modify host Name
    • Sed-i ' a127.0.0.1 www.hiahia.com '/etc/hosts//Add host name in Hosts file
    • Required Packages (Arp;apr-util;pcre for httpd dependencies)
      httpd-2.4.34:http://httpd.apache.org
      apr-1.6.3;apr-util-1.6.1:https://apr.apache.org/
      Pcre-8.37:https://ftp.pcre.org/pub/pcre/
2. Source code compilation and installation

(1) Installation dependent APR

tar -jxvf apr-1.6.3.tar.bz2 -C /usr/src/    //解压源码包
cd /usr/src/apr-1.6.3    //进入解压的目录
./configure --prefix=/usr/local/apr    //指定安装目录
make && make install    //编译并安装

(2) Install dependent Apr-util

tar -jxvf apr-util-1.6.1.tar.bz2 -C /usr/src/
cd /usr/src/apr-util-1.61
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr    //指定安装目录和apr安装位置
make && make install

(3) Install dependent Pcre

tar -jxvf pcre-8.37.tar.bz2 -C /usr/src/
cd /usr/src/pcre-8.37
make && make install

(4) Installation httpd

tar -zxvf httpd-2.4.34 -C /usr/src/    //解压httpd源码包
cd /usr/src/httpd-2.4.34
./configure --prefix=/usr/local/httpd --enable-so --enable-charset-lite --enable-rewrite --enable-cgi --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre    //配置安装选项

Options

--prefix: Specifying the program installation directory

--ENABLE-SO: Start dynamic load module support, make it extensible; is the core module to provide DSO support

--enable-rewrite: Start Page address rewriting function for website optimization and directory Migration maintenance

--enable-charset-lite: Enable character set support to support Web pages that use various character set encodings

--ENABLE-CGI: Enable CGI scripting support, extend the application access of the Web site, usually the execution of CGI involves security issues, any system can be called, so it is common to put CGI in a specific directory to execute

--WITH-APR: Specify APR installation directory

--with-apr-util: Specify Apr-util installation directory

--with-pcre: Specify PCRE installation directory

Make && make install//compile and install

3. Confirm the installation results
ls /usr/local/httpd

Service Catalog:/usr/local/httpd/

Master configuration file:/usr/local/httpd/conf/httpd.conf

Web directory:/usr/local/httpd/htdocs/

Service script:/usr/local/httpd/bin/apachectl

Execution Program:/USR/LOCAL/HTTPD/BIN/HTTPD

Access log:/usr/local/httpd/logs/access_log

Error log:/usr/local/httpd/logs/error_log

4. Optimize Execution path
ln -s /usr/local/httpd/bin/* /usr/local/bin/    //添加到PATH搜索路径中,用户不需完整命令路径即可使用
5. Add httpd to system service
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd    //拷贝默认脚本文件到系统控制目录
vim /etc/init.d/httpd#chkconfig:35 66 66     //服务识别参数,指定3、5级别顺序启动标识号#description:Startup script for the Apache HTTP Server    //文件开头添加chkconfig识别配置,不添加chkconfig添加服务时报错

chkconfig --add httpd           //将httpd添加为系统服务
Vi. Basic configuration of the HTTPD server Deployment process for 1.WEB sites

(1) Determine the website name, IP address

Need to apply for a legitimate public IP address, and to the DNS provider to apply for a domain name, the corresponding host DNS resolution record
Internal use of the company can be configured independently, without public IP, but to use the internal domain name can be set up DNS and the corresponding resolution record added, modify the/etc/hosts file to improve the local resolution speed

(2) Configure and start the HTTPD service

vim /usr/local/httpd/conf/httpd.conf            //编辑httpd主配置文件...   ServerName www.hiahia.com:80...//寻找该行(97行) ,设置网站名称

apachectl -t    //检测httpd.conf文件是否有语法错误;“Syntax OK”则无误
/etc/init.d/httpd start     //启动httpd服务
netstat -utpln | grep httpd    //过滤是否开启服务

(3) Deploying Web pages

Compile and install the HTTPD service, the Web site root directory is the/usr/local/httpd/htdocs directory, the Web page document is copied to this directory; Index.html test Web page is provided by default

(4) Accessing the website home page on the client

(5) Viewing site visits

Access log:/usr/local/httpd/log/access_log

Error log:/usr/local/httpd/log/error_log

2.httpd.conf configuration file

Apache Official Document: http://httpd.apache.org/docs/2.4/

(1) Global configuration Items

ServerRoot: Service Catalog

ServerAdmin: Admin Mailbox

User: Identity of users running the service; default daemon

Group: The identity of the groups running the service; default daemon

ServerName: Domain name of the Web server

DocumentRoot: root directory of Web document

Listen: IP address, port number of the listener, default 80 port

DirectoryIndex: Default index page file; default Home file index.html

Errorlog: Location of error log files

Customlog: The location of the access log file; default type common

LogLevel: Logging level, default is warn (warning)

Timeout: Network connection timed out, default is 300 seconds

KeepAlive: Whether to remain connected, optional on or off

Maxkeepaliverequests: Maximum number of requested files per connection

KeepAliveTimeout: Time-out when maintaining connection status

Include: Additional configuration files that need to be included

(2) Area Configuration items (common)

httpd-2.2.x
<directory/> Restricting access to the root directory
Options FollowSymLinks
AllowOverride None
Order Deny,allow
The order in which the access control policies are applied; Check the Forbidden setting first, all allowed without forbidden
Deny from all
Prohibit anyone from accessing this area
</Directory>
httpd-2.4.x
<directory/> Restricting access to the root directory
Options FollowSymLinks
Control options that allow symbolic links to be used, and whether to jump to the corresponding connection path when a symbolic connection is accessed
AllowOverride None
Override configuration in the implicit control file is not allowed; Do you want to find the. htaccess file as the configuration file
Require all granted
Allow anyone to access this area
</Directory>

Vii. Statistics of website visits 1. Deploying the Awstats Analysis System

(1) Installing the Awstats package

awstat:http://www.awstats.org/

tar -zxvf awstats-7.7.tar.gz    //解包
mv awstats-7.7 /usr/local/awstats    //移动解压缩目录;该软件为绿色版直接可用

(2) Modify the httpd configuration file

CGI script module support and access permissions settings

(3) Installing Perl environment support

yum -y install perl perl-devel perl-CGI

(4) Create a profile for the site to be counted

cd /usr/local/awstats/tools/    //进入工具目录
chmod +x awstats_configure.pl    //给予配置脚本执行权限
./awstats_configure.pl    //运行配置脚本
Specify the HTTPD Master profile path

Set the log type

To create a configuration file for a specified Web site

Subsequent configuration work

Next, the HTTPD service will be restarted automatically (assuming/ETC/INIT.D/HTTPD script exists)
If you need to count other sites, run again./awstats_configure.pl

(5) Modify the site statistics configuration file

vim /etc/awstats/awstats.www.hiahia.com.conf50   LogFile="/usr/local/httpd/logs/access_log"    //指定httpd访问日志所在位置
mkdir /var/lib/awstats    //创建数据存放目录

(6) Perform log analysis and set up recurring scheduled tasks

chmod +x awstats_updateall.pl           //给予更新脚本执行权限
./awstats_updateall.pl now      //立即更新awstats信息并统计到统计数据库中
crontab -e*/5 * * * *  /usr/local/awstats/tools/awstats_updateall.pl now
/etc/init.d/crond start && chkconfig --level 35 crond on
2.web Access Awstats Analysis System

Browser Access http://192.168.1.151/awstats/awstats.pl?config=www.hiahia.com

You can also write Web page skipping, automatic Web page skipping, simplified access to the address
Vim/usr/local/httpd/htdocs/awstats.html
<meta http-equiv=refresh content= "0;url=http://192.168.1.151/awstats/awstats.pl?config=www.hiahia.com" >
<body>
</body>
Browser access: http://192.168.1.151/awstats.html

Apache Website Services

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.