Simple WWW server set up Web servers

Author: Small P
from: League of Legends Community
Summary: Linux why so popular, its biggest feature than a powerful, stable performance of the application server. Like WWW, MAIL, FTP, DNS and SMB etc; In this article, we start with some basic operation of the Web server. . .

 
   1. On the WWW and URL; 
    format 1.1 URL's;  
   1.1.1 protocol;  
   1.1.2 host address;  
   1.1.3 directory;  
   1.1.4 port;  
   type 2. www host system; 
    2.1 of the Apache history and prospects;  
   2.2 the Apache 2 is mounted;  
   2.2.1 source installations;  
   configuration of 3. Apache 2; 
    3.1 the apache2.conf;  
   3.2 the conf.d;  
   3.3 the httpd.conf;  
   3.4 Magic;  
   3.5 of ports.conf;  
   3.6-MODS Available;  
   3.7 sites- Available;  
   3.8 / var / WWW;  
   4. Apache management; 
    4.1 start and stop Apache;  
   4.2 Apache log file;  
   5. virtual host configuration;  
   6. configure Apache proxy; 
    6.1 client agent configuration;  
   6.2 proxy server configuration;  
   6.2.1 configuration Apache on the firewall;  
   6.2.2 WWW server in LAN configuration;  
   7. About herein;  
   8. update log;  
   9. documented;  
   10 related documents; 
   


+++++++++++++++++++++++++++++++++++++++++++
text
++++++ +++++++++++++++++++++++++++++++++++++

If you are a Linux enthusiast, you may have mastered the basic knowledge of Linux and operation, without a doubt, you did not go to meet such a small achievement; why Linux is so popular? The biggest feature than a powerful, stable performance of the application server. Like WWW, MAIL, FTP, DNS and SMB etc; In this paper, we start with some basic operation of Web servers, used from beginners attitude, so that we fully correct understanding of Apache and other servers;


1. On the WWW and URL;

WWW is the World Wide Web acronym, translates World Wide Web, it can engage the text, graphics, video and audio and other multimedia, and through hypertext (HyperText) way to pass information to the entire world through the Internet;
for example: In enter the address bar of the browser on the Web site on linuxsir "http://www.linuxsir.org", you can log browsing information, "http://www.linuxsir.org" is a URL (Uniform Resource Locator, the same resource Locator), "www.linuxsir.org" is the host name is in DNS FQDN (fully Qualified domain name, in full compliance with the standard domain name), plus a host name that is above a unique Internet domain name income . Because the computer recognizes only the network IP, so the real IP linuxsir station is through DNS resolution www.linuxsir.org and found, and then after the protocol data to the www in front of you;


1.1 URL format; the

<protocol>: // <host address> [: port] / <directory>


1.1.1 protocol;

including http, ftp, news, gopher and telnet several common agreement. Which, http is the use of "http host port, usually port 80", using ftp "ftp host port, usually port 21." Note: 80 and 21 are services provided by the host, not the client's port.

1.1.2 host address;

when entering the host name (domain name), must let the host name to get the corresponding IP via a translator. The translator is / etc / hosts or /etc/resolv.conf set up inside the outside to provide normal www server, the host name must want everybody to be translated to IP, which need to apply for a legitimate domain name;

1.1. 3 directory;

that is, URI (uniform resource Indicator, a uniform resource locator), if you go to the home page of the site in the following pages directory, then you enter the name of the directory and the page directly, you can get the data directly to that page. If only enter the name of the directory page, and did not enter the name of the page, the server will automatically determine (with its own settings for server), whether there is in this directory as the default page name;

1.1.4 port;

when connected when a Web site, enter "http://that.host.name" will actively try to use port 80 to the other side of the host connection, but if you do not want to use the port. Take, for example, such as your site uses port 8080 to the www service, unless you use a firewall port mapping, or direct input "http://your.host.name" will result in the address bar unable to connect to your www server, because it will take the initiative to connect to port 80, so they are here to tell the browser to the server requests a service which port. That is written "http://your.host.name:8080" can connect to other ports 8080;


Type 2. www host system;

it can generally be divided into two types:

One is the IIS Windows system + MS SQL + ASP WWW server is relatively easy on www host this hypothesis, but due to certain characteristics of the windows, they are easily damaged by hackers;

Another is Apache + MySQL (PostgreSQL) + PHP's www server (referred to as LAMP) on a Linux system, there is a certain degree of difficulty on this server set up, especially in the upgrade and maintenance, but if set up properly, it hardware requirements, performance, security, etc., are relatively better, here we come to introduce the main Apache erection;


2.1 Apache history and prospects;

in 1995, the National Computer Security Association (NCSA) developers to create NCSZ Global Network Services software, its biggest feature is the HTTP daemon, it is easier to configure than the time CERN server from the source and create, but also due to lack of time other server software, he quickly became popular. But then, the core developers of the server almost left the NCSA, some users themselves set up an organization to manage patches they write, so the Apache Group came into being. They put the server software called Apache. A patchy server from Apache pronunciation, meaning full patch server. Apache now has slowly become the Internet's most popular Web server software. In all of the Web server software, Apache absolute dominance, far ahead of Microsoft IIS ranked second. If you are interested in it, you can visit the Apache official website: http: //www.apache.org. Apache is one of free software, like other free software, they are free from the many developers put a lot of time and effort to implement and gradually improve, so we have reason to believe that Apache's development prospects will be better .


2.2 Apache installation 2;

software installation is not difficult, you can download the source code package to install on www.apache.org, can also be used for each operating system comes with the package manager to install software, such as my system is Ubuntu , you can be in a terminal:

xiaop@xiaop-laptop:~$ sudo apt-get install apache2

Different systems have their own package management, they were all similar;

2.2.1 use the source code installation;

(1) the source code
xiaop@xiaop-laptop:~# lynx http://www.apache.org/dist/httpd/httpd-2_0_NN.tar.gz

NN represents the version number of the currently used

(2) decompressing

xiaop@xiaop-laptop:~# gzip -d httpd-2_0_NN.tar.gz

or
xiaop@xiaop-laptop:~# tar xvf httpd-2_0_NN.tar

(3) configuration.
xiaop@xiaop-laptop:~httpd-2_0_NN# ./configure --prefix= /usr/local/apache

It represents Apache will be installed in the / usr / local / apache directory

(4) Compile and install

xiaop@xiaop-laptop:~httpd-2_0_NN# make

xiaop@xiaop-laptop:~httpd-2_0_NN# make install

(5) Testing
xiaop@xiaop-laptop:~httpd-2_0_NN# /usr/local/apache/bin/apachectl start


3. Apache 2 configuration;

after installing apache2, can view the files in the / etc / apache2 / directory:

xiaop@xiaop-laptop:/etc/apache2$ ls -lh
总用量 35K
-rw-r--r-- 1 root root  24K 2007-01-16 02:10 apache2.conf
drwxr-xr-x 2 root root  104 2007-06-12 21:07 conf.d
-rw-r--r-- 1 root root  895 2007-01-16 02:11 envvars
-rw-r--r-- 1 root root    0 2007-05-17 17:34 httpd.conf
drwxr-xr-x 2 root root 2.5K 2007-07-18 08:43 mods-available
drwxr-xr-x 2 root root  608 2007-05-17 17:36 mods-enabled
-rw-r--r-- 1 root root   10 2007-05-17 17:34 ports.conf
drwxr-xr-x 2 root root   72 2007-05-19 16:47 sites-available
drwxr-xr-x 2 root root   80 2007-05-17 17:34 sites-enabled


Apache2.conf 3.1;

the Apache 2.0's main configuration file for the apache2.conf; my profile stored in /etc/apache2/apache2.conf;
to view the file contents will find the following line in the vicinity of 184:

# Include module configuration:
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf

# Include all the user configurations:
Include /etc/apache2/httpd.conf

# Include ports listing
Include /etc/apache2/ports.conf

# Include generic snippets of statements
Include /etc/apache2/conf.d/

Apache2 can be seen that depending on the configuration of the function of the configuration file is divided, so that even easier;


3.2 conf.d;

next to the profile of an additional piece, by default, provides only charset piece,

xiaop@xiaop-laptop:/etc/apache2/conf.d$ cat charset
AddDefaultCharset UTF-8

If necessary we can modify the default encoding is GB2312, ie the contents of the file is: AddDefaultCharset GB2312


3.3 httpd.conf;

usually an empty file, the following may be added after the instruction set;

Here we look at a few instructions in httpd.conf, after the "#" added explanatory notes;

Port 80                   #定义了web服务器的侦听端口,默认值为80,它是TCP网络端口之一。若写入多个端口,以最后一个为准。

User apache                   #一般情况下,以nobody用户和nobody组来运行web服务器,因为web

Group apache               # 服务器发出的所有的进程都是以root用户身份运行的,存在安全风险。

ServerAdmin root@localhost              #指定服务器管理员的E-mail地址。服务器自动将错误报告到该地址。

ServerRoot /etc/httpd                  #服务器的根目录,一般情况下,所有的配置文件在该目录下

ServerName new.host.name:80                #web客户搜索的主机名称

KeepAliveTimeout 15                   #规定了连续请求之间等待15秒,若超过,则重新建立一条新的TCP连接

MaxKeepAliveRequests 100                  #永久连接的HTTP请求数

MaxClients 150                   #同一时间连接到服务器上的客户机总数

ErrorLog logs/error_log               #用来指定错误日志文件的名称和路径

PidFile run/httpd.pid                 #用来存放httpd进程号,以方便停止服务器。

Timeout 300                           #设置请求超时时间,若网速较慢则应把值设大。

DocumentRoot /var/www/html              # 用来存放网页文件


3.4 magic;

file contains data relating mod_mime_magic module, generally do not need to modify it;


3.5 ports.conf;

was listening server IP and port settings of the profile,

xiaop@xiaop-laptop:/etc/apache2$ cat ports.conf
Listen 80


3.6 mods-available;

directory file .load some .conf and load profile for the various modules of the system can be used, while the lower mods-enabled directory is a symbolic link pointing to these profiles from the profile apache2 .conf can be seen, the system to load the module mods-enabled directory, that is, only by creating a system profile in mods-available directory symbolic link to this directory in the load module. And the system also provides two command a2enmod a2dismod and for maintaining these symbolic links. Both commands provided by apache2-common package. All kinds of command is very simple: a2enmod [module] or a2dismod [module]


3.7 sites-available ;

Configuration file directory is a good site, the sites-enabled directory is a symbolic point to these profiles are connected, are connected to the system via the symbols in the symbol only use site connection sites-enabled directory numbers with a prefix, such as 000 -default, this number is used to determine the boot sequence, the smaller the number, the higher priority start. a2ensite system provides two command symbols and a2dissite for maintaining connections. Both commands provided by apache2-common package;


3.8 / var / www;

default will be published on the page file should be placed under / var / www directory, this default value can be modified through the main configuration file with the option DocumnetRoot


4. Apache management;


4.1 Starting and stopping Apache;

root@xiaop-laptop:/#/etc/init.d/apache2 start

root@xiaop-laptop:/#/etc/init.d/apache2 stop


4.2 Apache log files;

the Apache's files to include access and error logs. Access logging process all the requests of the server, the major record customer information, through which we can know who visited the site, what time of the visit, and so what content access yes. Error Log is record the details of server errors and how to deal with and so on. Where the log file is the configuration file httpd.conf predetermined by the Lord. Here is an example to illustrate its format:

An error message:

[Mon sep 22 14:32:52 2003] [error] [client 127.0.0.1] client denied by server configuration: /export/home/live/ap/htdocs/test

Let's see what this wrong information, said:
[Mon sep 22 14:32:52 2003]           #错误发生的时间

[error]         #表示错误的级别。有debug,info,notice,warn,error,crit,alert,emerg,这些级别由低到高表示了错误的严重性

[client 127.0.0.1]         #表示客户端IP地址

client denied by server configuration: /export/home/live/ap/htdocs/test    #标是错误的具体信息

Access log wording:

127.0.0.1 - xiaop [22/sep/2007:13:55:36 -0800] "GET /apache_pb.gif HTTP/1.0" 200 2326


Note:

127.0.0.1 # represents access to this server, client IP address.

xiaop # represents the user's login name.

[22 / sep / 2003: 13: 55: 36 -0800] # server to complete the client request time in the format [day / month / year: hours: minutes: seconds Time Zone]

"GET /apache_pb.gif HTTP / 1.0" # representation of the resource used by clients to access

# 200 record is returned by the server to the client status code; 200 indicates success, beginning with 4 to indicate access error

# 2326 represents the total number of bytes sent to the client. If "-" indicates not find access to resources

but in practical applications, for large sites, log files often grow quickly, is not conducive to our queries, reduce the efficiency of the server, and take up a lot of disk space, so we have the log regular maintenance;


The virtual host configuration;

virtual computer that provides services to a plurality of www separate header on a www server, each with its own domain directory and configuration, equivalent to a host into multiple hosts, virtual host technology for less than the number of hosts, but want to provide an independent Web service for different user needs very effective. For a company, the use of expensive domain name server provides only one service, it seems unwise, but now more and more companies prefer to use multiple domain names services on a single server, set up different websites, do so the benefits are obvious.

There are two ways to support Apache virtual hosts, one is IP-based virtual hosts, and the other is name-based virtual hosts. Name-based virtual hosts using the same IP address to configure different virtual hosts, which make up a problem due to lack of IP addresses brought. Configure name-based virtual hosting is quite simple, you just have to configure your DNS server so that each host name corresponds to the correct IP address, and then configure the Apache HTTP Server to enable it to recognize different host name on it.

Suppose we set up a multimedia production company, has an Apache server and an IP address: 192.168.1.1 to run two businesses, one for e-commerce sites, the domain name www.business.media.com, another site for teaching , domain name www.teaching.media.com. In the first DNS server in the domain www.business.media.com and www.teachin .... conf on it.

NameVirtualHost 192.168.0.1

<VirtualHost 192.168.0.1>
ServerName www.business.media.com
DocumentRoot /var/www/html/business
</VirtualHost>

<VirtualHost 192.168.0.1>
ServerName www.teaching.media.com
DocumentRoot /var/www/html/teaching
</VirtualHost>

And IP-based virtual hosts requires the use of different IP addresses to distinguish between different virtual server, which requires the use of multiple network cards, tied to different IP addresses to different cards, or bundling multiple IP addresses on a network card . Suppose we host's IP address is 192.168.0.1 (www.media.com), and another two IP addresses do not:

<VirtualHost 192.168.0.2>
ServerAdmin webmaster@ business.media.com
DocumentRoot /var/www/html/business
ServerName www.business.media.com
ErrorLog /var/www/html/business/logs/error_log
TransferLog /var/www/html/business/logs/access_log
</VirtualHost>

<VirtualHost 192.168.0.3>
ServerAdmin [email protected]
DocumentRoot /var/www/html/teaching
ServerName www.teaching.media.com
ErrorLog /var/www/html/teaching/logs/error_log
TransferLog /var/www/html/teaching/logs/access_log
</VirtualHost>


6. Configure Apache proxy;

proxy server is a transit station network information service. If we liken the Apache proxy server into the agent's words, when consumers buy something to the agents, the agents if any, can be sold directly to consumers, if not, the agent purchase the manufacturers, then sell consumer.
This has the following advantages:

(1) increase the access speed;
(2) act as a firewall, an increase of security;
(3) can filter some bad sites;
(4) has a cache function;
(5) IP cost savings;

Proxy servers can be divided into two types: client agent and server-side proxy;

Here we illustrate a respective configuration after several instructions explain;

ProxyRequest On/Off         #启用或者禁用Apache代理服务。
CacheRoot "/etc/httpd/proxy"            #代理缓存的根目录。
CacheSize 5            #代理缓存的大小。
CacheGcInterval 4             #设定运行管理缓存的无用数据搜集程序的时间间隔
CacheMaxExpire 24            #文件过期时间。
CacheDefaultExpire 1            #指定未包含过期信息文件的有效期。
NoCache a-domain.com another-domain.edu               #该网站的文件将不被缓存。


6.1 Configuration of the client agent;

(1) modify the instruction in the relevant /etc/httpd/conf/httpd.conf
(2) modify /etc/httpd/conf/httpd.conf, add access control to the directory agent

Order deny, the allow
Deny from All
the Allow .your-domain.com from

(. 3) restart httpd


6.2 server-side proxy configuration;

server-side proxy and the client agent is different, it is installed on the Apache server firewall, use it to provide access to the WWW proxy server. This approach to WWW server and an external separated, improves security, and the user, the same does not seem to change. Assume WWW server internal LAN IP address is 192.168.0.2, the internal firewall host IP address is 192.168.0.5, the external IP address is 192.9.202.1.

6.2.1 Apache configuration on the firewall;

(1) add a virtual host /etc/httpd/conf/httpd.conf in.

<VirtualHost 192.9.201.1>
ServerAdmin [email protected]
DocumentRoot /www/docs/business.media.com
ServerName www.business.media.com
ErrorLog logs/business.media.com-error_log
CustomLog logs/business.media.com-log_common
</VirtualHost>

(2) Configuration LAN DNS server, the www.business.media.com point 192.9.201.1.


6.2.2 LAN internal WWW server;

in the Linux environment, there is a very popular proxy server software --Squid. His function is very powerful, supports proxy HTTP, FTP, Gopher, SSL, and WAIS and other agreements, and simple to set up, and then just a little change in the configuration file on it;


7. About this;

this is just simply say what principle is simple www server and application, not related to advanced applications, primarily for beginners, there are also deficiencies please enlighten;


8. Update log;


9. reference documentation;

"Apache2 Installation and Configuration"


10. The related documents;

"apache2 Installation and Configuration"

Reproduced in: https: //www.cnblogs.com/licheng/archive/2008/01/21/1047624.html

Guess you like

Origin blog.csdn.net/weixin_33860737/article/details/92630808