Website administrator-LINUX Server SETUP-WWW-Linux Enterprise Application-Linux server application information. For more information, see the following section. ++ ++
Body
++ ++
If you are a Linux enthusiast, you may have mastered basic Linux knowledge and operations. Without a doubt, you will not meet such a small achievement. Why is Linux so popular? Its biggest feature is powerful and stable server applications. Such as WWW, MAIL, FTP, DNS, and SMB. In this article, we start with some of the most basic operations on the Web server, starting with the attitude of beginners, let everyone learn how to use linux to assume a server of their own.
1. About WWW and URL;
WWW is the abbreviation of World Wide Web. It is translated into a global Wide area network. It can be used to join texts, images, images, sounds, and other multimedia and use Hyper Text, transmit information to all parts of the world through the Internet;
For example: Enter "http://www.linuxsir.org" in the address bar of the browser, you can log on to the linuxsir site to browse information, where "http://www.linuxsir.org" is the URL (Uniform Resource Locator, the same Resource Locator ), "www.linuxsir.org" is the host Name, that is, the FQDN (Fully Qualified Domain Name, Fully compliant with the standard Domain Name) in DNS, that is, the host Name plus the Domain Name obtained by a unique Name on the Internet. Because the computer only recognizes IP addresses in the network, the real IP address of the linuxsir station is found through DNS resolution www.linuxsir.org and then transmitted to your eyes through the www protocol;
1.1 URL format;
<协议> :// <主机地址> [: Port]/ <目录>
1.1.1 protocol;
Common protocols include http, ftp, news, gopher, and telnet. Http uses "http port of the host, usually port 80", and ftp uses "ftp port of the host, usually port 21 ". Note: Both 80 and 21 are services provided by the host, rather than the client port.
1.1.2 host address;
When you enter the host name (domain name), you must allow the host name to obtain the corresponding IP address through the translator. The translator is/etc/hosts or/etc/resolv. when the configuration in conf provides a normal www server, the host name must be translated to an IP address. Therefore, you need to apply for a valid domain name;
1.1.3 directory;
That is, URI (Uniform Resource Indicator, unified Resource Locator). If the website webpage you want to go to is under the directory of the home page, enter the Directory and webpage name directly, you can directly obtain the data on that webpage. If you only enter the Directory and webpage name, and do not enter the webpage name, the server automatically determines (related to the settings of the server ), whether the default webpage name is set in this directory;
1.1.4 port;
When you connect to a website, entering "http://that.host.name" will take the initiative to use port 80 to try to connect to the host of the other party, but if you do not want to use this port. For example, if your website uses port 8080 for www Service, otherwise, entering the "http://your.host.name" result in the address bar will not be able to connect to your www server, because it will actively connect to port 80, so here we need to tell the browser to request the server which port is the service. That is, write "http://your.host.name: 8080" can connect to the other side of the port 8080;
2. Types of www host systems;
Generally, there are two types:
One is the Windows system's IIS + ms SQL + ASP WWW server, which is relatively easy to assume on the www host, but due to some features of windows, it is easy to be damaged by hackers;
The other is the www server (LAMP) of Apache + MySQL (PostgreSQL) + PHP on the Linux system, which is difficult to set up, especially in terms of upgrade and maintenance, but if it is set up properly, its hardware requirements, performance, and security are relatively better. Next we will mainly introduce the setup of Apache;
2.1 History and prospects of Apache;
In 1995, a developer of the National Computer Security Association (NCSA) created the NCSZ global network service software. Its biggest feature was the HTTP genie program, it was easier to configure and create the source code than the CERN server at that time. Due to the lack of other server software at that time, it soon became popular. But later, almost all core developers of the server left NCSA, and some users set up an organization to manage the patches they prepared, so Apache Group came into being. They call the server software Apache. Apache originated from the pronunciation of A patchy server, which means A server filled with patches. Apache has gradually become the most popular Web server software on the Internet. Among all Web server software, Apache occupies an absolute advantage, far ahead of Microsoft IIS, which ranks second. If you are interested in it, you can visit the official Apache website: http://www.apache.org. As one of the Free Software, Apache, like other free software, is implemented and gradually improved by a large number of free developers who have invested a lot of time and energy, therefore, we have reason to believe that the development prospects of Apache will be better.
2.2 installation of Apache 2;
It is not difficult to install the software. You can download the source code package on www.apache.org to install the software, or install the software package management software that comes with each operating system, for details about how to download and install the SDK, refer to a post I posted earlier. Enter the following in the terminal:
The main configuration file of Apache 2.0 is apache2.conf; the configuration file is saved in/etc/apache2/apache2.conf;
The following content will be found near row 184th when you view this file:
# Include module configuration:
Include/etc/apache2/mod-enabled/*. load
Include/etc/apache2/mod-enabled/*. conf
# Include all the user invocations:
Include/etc/apache2/httpd. conf
# Include ports listing
Include/etc/apache2/ports. conf
# Include generic snippets of statements
Include/etc/apache2/conf. d/
We can see that apache2 separates the configuration files based on different configuration functions, which is more conducive to management;
3.2 conf. d;
Is an additional part of the configuration file. By default, only charset fragments are provided,
Qiong @ qiong-love:/etc/apache2/conf. d $ cat charset
Adddefacharcharset UTF-8
If necessary, we can change the default encoding to GB2312, that is, the file content is: AddDefaultCharset GB2312
3.3 httpd. conf;
It is usually an empty file. You can add the following commands when setting it later;
Next, let's take a look at several commands in httpd. conf. "#" is followed by comments;
Port 80 # defines the listening Port of the web server. The default value is 80, which is one of the TCP network ports. If multiple ports are written, the last port prevails.
User apache # generally, the web server runs with a nobody User and a nobody group because
All processes sent by the Group apache # Server Run as root, which has security risks.
ServerAdmin root @ localhost # specify the email address of the server administrator. The server automatically reports the error to this address.
ServerRoot/etc/httpd # the root directory of the server. Generally, all configuration files are under this directory.
ServerName new. host. name: 80 # name of the host searched by the web Client
KeepAliveTimeout 15 # specifies that a continuous request is waiting for 15 seconds. If the request exceeds 15 seconds, a new TCP connection is established.
MaxKeepAliveRequests 100 # Number of HTTP requests for permanent connection
MaxClients 150 # Total number of clients connected to the server at the same time
ErrorLog logs/error_log # used to specify the name and path of the Error Log File
PidFile run/httpd. pid # is used to store the httpd process number to stop the server.
Timeout 300 # Set the request Timeout time. If the network speed is slow, set the value to a large value.
DocumentRoot/var/www/html # used to store webpage files
3.4 magic;
The file contains data about the mod_mime_magic module, which generally does not need to be modified;
3.5 ports. conf;
The configuration file set for the server listening IP address and port,
The directory contains some. conf and. load file, which can be used in the system to load configuration files of various modules, while the directory of the mod-enabled is a symbolic connection to these configuration files, as shown in the configuration file apache2.conf, the system loads the module through the directory named "mod-enabled". That is to say, the system only loads the module by creating the configuration file in the directory named "mod-available" with symbolic connections. The system also provides two Commands: a2enmod and a2dismod to maintain these symbolic connections. These two commands are provided by the apache2-common package. Various commands are also very simple: a2enmod [module] Or a2dismod [module]
3.7 sites-available;
The configuration file of the configured site is in the directory, and the sites-enabled directory is a symbolic connection pointing to these configuration files, the system uses these symbolic connections to connect with a digital prefix, such as 000-default, in the sites-enabled directory of the site. The smaller the number, higher startup priority. the system provides two commands, a2ensite and a2dissite, to maintain these symbolic connections. These two commands are provided by the apache2-common package;
3.8/var/www;
By default, the web page file to be published should be placed in the/var/www directory. This default value can be modified in the same way as the "expose netroot" option in the main configuration file.
4. Apache management;
4.1 Start and Stop Apache;
Root @ qiong-love: // #/etc/init. d/apache2 start
Root @ qiong-love: // #/etc/init. d/apache2 stop
4.2 Apache log files;
Apache logs to files mainly include access logs and error logs. The access log records all the request processes of the server. It mainly records the customer's information. Through this log, we can know who accessed the website and when to visit it, what is the accessed content. The error log records the details of server errors and how to handle them. The location of the log file is specified by the above main configuration file httpd. conf. The following is an example of 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 take a look at what this error message represents:
[Mon sep 22 14:32:52 2003] # error occurrence time
[Error] # indicates the error level. Debug, info, notice, warn, error, crit, alert, and emerg are available. These levels indicate the severity of the error from low to high.
[Client 127.0.0.1] # indicates the client IP Address
Client denied by server configuration:/export/home/live/ap/htdocs/test # mark the error details
127.0.0.1 # indicates the IP address of the client accessing this server.
Qiong # indicates the user's login name.
[22/sep/2003: 13: 55: 36-0800] # time when the server completes the client request, in the format of [day/month/year: hour: minute: Second Time Zone]
"GET/apache_pb.gif HTTP/1.0" # indicates the method used by the client to access this resource.
200 # the status code returned by the server to the customer is recorded. 200 indicates that the status code is successful, and 4 indicates that the access error occurs.
2326 # indicates the total number of bytes sent to the client. If it is "-", the access resource is not found.
However, in practical applications, for large websites, log files often grow rapidly, which is not conducive to our query, reduces server efficiency and occupies a large amount of disk space, therefore, we must regularly maintain logs;
5. Configure the VM;
A vm provides www services for multiple independent domain names on a www server. Each domain name has its own directory and configuration, which is equivalent to dividing a host into multiple hosts, the virtual host technology is very effective for users who want to provide independent Web services. It seems unwise for a company to use expensive servers to provide only one Domain Name Service. More and more companies prefer to use multiple domain name services on one server, the benefits of setting up different websites are obvious.
Apache supports Virtual Hosts in two ways: IP-based virtual hosts and name-based virtual hosts. Name-based virtual hosts use the same IP address to configure different virtual hosts, which makes up for problems caused by insufficient IP addresses. The name-based virtual host configuration is quite simple. You only need to configure the DNS server so that each host name corresponds to the correct IP address, then configure Apache HTTP Server so that it can recognize different host names.
Suppose we have set up a multimedia production company with an Apache server and an IP address 192.168.1.1 to run two types of business: an e-commerce website with the domain name www.business.media.com, the other is the teaching website with the domain name www.teaching.media.com. First, you can set the domain name www.business.media.com and www. teachin... conf on the DNS server.
IP-based virtual hosts require different IP addresses to be used to distinguish different virtual hosts. This requires multiple NICs to be used to bind different IP addresses to different NICs, alternatively, you can bind multiple IP addresses to a network card. Assume that the IP address of our host is 192.168.0.1 (www.media.com), and there are two other IP addresses:
A proxy server is a transfer station for network information services. If we compare the Apache proxy server to an agent, when a consumer buys something from the agent, if the agent has it, it can be directly sold to the consumer. If not, the agent will purchase the goods from the manufacturer, then sell it to consumers.
This method has the following benefits:
(1) Improved access speed;
(2) act as a firewall to increase security;
(3) Some poor websites can be filtered out;
(4) cache function;
(5) Saving IP overhead;
The proxy server can be divided into two types: client proxy and server proxy;
Next we will explain several instructions and then illustrate their respective configuration methods;
ProxyRequest On/Off # enable or disable the Apache proxy service.
CacheRoot "/etc/httpd/proxy" # root directory of proxy cache.
CacheSize 5 # Proxy Cache size.
CacheGcInterval 4 # Set the interval between useless data collection programs running the management Cache
CacheMaxExpire 24 # file expiration time.
CacheDefaultExpire 1 # specify the validity period of the file that does not contain the expired information.
NoCache a-domain.com another-domain.edu # files for this site will not be cached.
6.1 configure the client proxy;
(1) modify the commands in/etc/httpd/conf/httpd. conf.
(2) Modify/etc/httpd/conf/httpd. conf and add access control to the proxy directory.
Order deny, allow
Deny from all
Allow from .your-domain.com
(3) Restart httpd
6.2 server-side proxy configuration;
The server-side proxy is different from the client-side proxy. It installs the Apache server on the firewall and uses it to provide proxy access to the WWW server. This method separates the WWW server from the external, improving the security. For users, it seems that there is no change. Assume that the IP address of the WWW server in the internal LAN is 192.168.0.2, the internal IP address of the firewall host is 192.168.0.5, and the external IP address is 192.9.202.1.
(2) configure the DNS server in the LAN and direct www.business.media.com to 192.9..1 .1.
6.2.2 configure the WWW server in the LAN;
In Linux, Squid is a popular proxy server software. It is very powerful and supports proxies for HTTP, FTP, Gopher, SSL, WAIS, and other protocols, and is easy to set. You only need to make slight changes in the configuration file;
7. About this article;
This article only briefly introduces the principles and simple applications of the www server. It does not involve advanced applications and is mainly convenient for beginners. Please give us more advice on the shortcomings;
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.