Introduction to Nginx
Introduction to common Web servers
Web servers are often referred to as WWW (World Wide Web) servers, HTTP servers, and their main function is to provide
On-line information browsing services, common Web servers under Linux and Uninx platforms are Apache, Nginx, LIGHTTPD, Tomcat
And so on, is Http://www.netcraft.com website 2014 recent statistics of each Web server market share. 650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/57/94/wKiom1Sec7bhlK4cAAHQOzPDiIo905.jpg "title=" Wpid-wss-share.png "width=" 680 "height=" 380 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:680px;height:380px; "alt=" Wkiom1sec7bhlk4caahqozpdiio905.jpg "/>
It can be seen that Apache has been on the Web server occupy "boss position", the main advantage lies in the open source code, there is a
Open development teams that support cross-platform applications, portability, and more. Microsoft Iis,iis is a set of service components
This includes Web servers, FTP servers, SMTP servers, and so on.
Nginx due to the late appearance, the market share has been on the rise, up to now, probably occupy 14.47%.
With respect to other Web services, Nginx mainly follows the advantages.
1.Nginx uses the latest epoll (Linux2.6 core) and Kqueue (FreeBSD) network I/O models to support high concurrent connections
Apache uses the traditional select model, and the derivation of the subprocess consumes more CPU resources than nginx.
2. Memory consumption is smaller, nginx+php (Fastcgi) in 30,000 concurrent connection, open 10 Nginx process, consumes 150M of memory.
3. Low cost, nginx follow BSD open source agreement, free to use, and can be used for commercial purposes
4. Simple configuration, support URL and other rewriting functions
2. Compile and install Nginx
Nginx is an open source software that can be installed on Microsoft, Unix, Linux and other systems, described here in centos6.6_x86-64
Compile and install the nginx1.6.2 version, of course you can also install other versions of the. Nginx Official website address is: www.nginx.org
On the official website can be seen in the various versions supported, Nginx compilation installation needs to be ready to compile the environment, the need for the environment, according to
The selected Nginx function is different, the main preparation gcc and so on, Nginx support third-party module, if gzip installed zlib library, etc.,
Here is the development environment that I prepared at compile time.
Yum Groupinstall "Development Tools" "Server Platform Development" Yum install-y zlib zlib-devel OpenSSL openssl-devel y Um install-y pcre-devel
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/57/94/wKiom1See-DRgGxLAAGyBOlCAhk668.jpg "title=" 1.jpg " Width= "680" height= "192" border= "0" hspace= "0" vspace= "0" style= "width:680px;height:192px;" alt= " Wkiom1see-drggxlaagybolcahk668.jpg "/>
Use the./configure--help to see each option and its meaning
The Nginx user and Nginx group are created before installing Nginx to run Nginx worker process with Nginx user identity.
Useradd-m-s/sbin/nologin nginx./configure--prefix=/application/nginx \ #将nginx安装在/application/nginx directory--user=ng INX \ #以nginx用户来运行worker process--group=nginx--with-http_ssl_module \ #支持ssl功能--with-h Ttp_flv_module \ #支持flv功能--with-http_gzip_static_module #支持gzip压缩makemake Install
You can choose the appropriate option according to the function you want to implement, and remind you to check if you are compiling each step of the installation.
Error occurred, to resolve each error after the next step, or the final compilation is not available, looking back
One step makes a mistake.
After compiling, you can view the/application/nginx directory, and you will find that the following content is rare.
3.Nginx start, stop, smooth restart
Nginx startup command is located in the/application/nginx/sbin directory of the only startup script Nginx, Start no need to add any
What parameters
/application/nginx/sbin/nginx, you can use the-C option if the profile is installed in a different directory when it is compiled
Set its directory, the default will look for the compiled directory/application/nginx directory under the Conf directory of nginx.conf, after startup
Can view the service process
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/57/91/wKioL1SegPOgwteWAAGdZpSkxSE818.jpg "title=" 2.jpg " Width= "680" height= "border=" 0 "hspace=" 0 "vspace=" 0 "style=" WIDTH:680PX;HEIGHT:97PX; "alt=" Wkiol1segpogwtewaagdzpskxse818.jpg "/>
As you can see, there may only be one master process and one worker process, and I see 3 of them because I modified the
Nginx.conf of Worker_processes 3;
If you see the above information, the surface nginx start normal, if not seen, please check the error message, this time to view the Web page, address
Enter the Nginx service host address in the column, you can see the information of Welcome to Nginx, the surface access is successful.
Nginx Stop, you can use the/application/nginx/sbin/nginx-s Stop command, you can also send a signal, such as
Kill-quit Nginx Main process number
Nginx Smooth Start, you can use the/application/nginx/sbin/nginx-s reload command, or send a signal such as
Kill-hup Nginx main process number, recommended/application/nginx/sbin/nginx-s Reload Way
4.Nginx Virtual Host Configuration
A virtual host uses a software and hardware technology that divides a server host running on the internet into a single "virtual"
Host, each virtual host can be a standalone website with full server functionality. In the Nginx configuration file (nginx.conf), each server is a virtual host, as follows:
http{ server { listen 80; server_name www.v3.com *.v3.com; access_log logs /access.log combined; location /{ index index.html index.htm; root html/v3; } } }
Note: In Nginx, each line should be followed by a Terminator (semicolon) used as a per-line/application/nginx/sbin/nginx-t
Will error, for example:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/57/94/wKiom1SehR2yXSI1AADpv7F1irs971.jpg "title=" 3.jpg " Width= "680" height= "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:680px;height:44px; "alt=" Wkiom1sehr2yxsi1aadpv7f1irs971.jpg "/>
In production, remember to check for errors and restarts after each modification.
4.1 Configuration of domain-based virtual hosts
Domain-based virtual host is the most common type of virtual host, multiple virtual hosts can share the same IP address, effectively solve the
The problem with insufficient IP address, the test configuration is as follows:
http { server { listen 80; #监听的端口 server_name www.v1.com; access_log logs/access.log combined; #访问日志存放的位置 location /{ index index.html index.htm; #会从左到右查找首页文件 root html/v1; # The location of the Web file is } } server { listen 80 ; server_name www.v2.com; access_log logs/access.log combined; location /{ index index.html index.htm; root html/v2; } } server { listen 80; server_name www.v3.com *.v3.com; access_log logs/access.log combined; location /{ index index.html index.htm; root html/v3; } }}
The above path uses the relative path, relative to the installation directory, in the V1, V2, v3 directory respectively placed 3 home file 650) this.width=650; src= http://s3.51cto.com/wyfs02/M02/57/92/ Wkiol1seiedzqkbvaacfxkg-aco969.jpg "title=" 4.jpg "width=" 680 "height=" 158 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:680px;height:158px; "alt=" wkiol1seiedzqkbvaacfxkg-aco969.jpg "/>
Below we use the Crul command to test the file of each domain name
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/57/92/wKioL1SeiMSweYjxAACgCWaL_Yg605.jpg "title=" 5.jpg " Width= "680" height= "101" border= "0" hspace= "0" vspace= "0" style= "width:680px;height:101px;" alt= " Wkiol1seimsweyjxaacgcwal_yg605.jpg "/>
You can see the contents of the home page file for each domain name
4.2 Configuration of virtual host based on IP address
It is easy to understand that IP-based virtual host is an IP address running on a virtual host, because there are not so many hosts on the hand
Here I configure a network card on the same host with aliases, an IP address configured on each alias
The command is:
Ifconfig eth0:1 192.168.1.6 broadcast 192.168.1.255 netmask 255.255.255.0 upifconfig eth0:2 192.168.1.7 broadcast 192.168 .1.255 netmask 255.255.255.0 up
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/57/94/wKiom1SeiuCTBwSAAAN3aJ-ASQ8528.jpg "title=" 6.jpg " Width= "680" height= "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:680px;height:250px; "alt=" Wkiom1seiuctbwsaaan3aj-asq8528.jpg "/>
http { server { listen 192.168.1.3:80; server_name 192.168.1.3; access_log logs/access.log combined; location /{ index index.html index.htm; root html/v1; } } server { listen 192.168.1.6:80; server_name 192.168.1.6; access_log logs/accesss.log combined; location /{ index index.html index.htm; root html /v2; } } server { listen 192.168.1.7:80; server_name 192.168.1.7; access_log logs /access.log combined; location /{ index index.html index.htm; root html/v3; } } }
Again, use the Crul command query, as follows:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/57/92/wKioL1SejEbAqCnXAAC_XBn7EzE345.jpg "title=" 7.jpg " Width= "680" height= "109" border= "0" hspace= "0" vspace= "0" style= "WIDTH:680PX;HEIGHT:109PX;" alt= "WKIOL1SEJEBAQCNXAAC _xbn7eze345.jpg "/>
The above is the IP-based virtual host.
4.3 Port-based virtual host
Create a virtual host based on a port that is different from the same IP address, such as
http { server { listen 80; server_name 192.168.1.3; access_log logs/ access.log combined; location /{ index index.html index.htm; root html/v1; } } server { listen 8081; server_ name 192.168.1.6; access_log logs/accesss.log combined; location /{ index index.html index.htm; root html/v2; } } server { listen 8080; server_name 192.168.1.7; access_log logs/access.log combined; location /{ index index.html index.htm; Root html/v3; } } }
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/57/92/wKioL1SejZvzV1o7AAC3St-iGOk524.jpg "title=" 8.jpg " Width= "680" height= "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:680px;height:86px; "alt=" Wkiol1sejzvzv1o7aac3st-igok524.jpg "/>
This article is from the "Devil of Tears" blog, please be sure to keep this source http://sepizi.blog.51cto.com/9773154/1596626
Simple Linux Nginx Tutorial