20150410--lnmp+nginx-02

Source: Internet
Author: User
Tags apache php

Catalogue

first, commonly used Web Introduction to the server 1

Second, Nginx Understanding of 1

Third, Nginx features 1

Iv. Supported operating systems: 2

Five, Nginx the installation of 2

Vi. Configuring a virtual host 3

Seven, Nginx Support PHP 4

Eight, configuration Nginx Expires Caching features 6

1 , overall configuration validity period: 6

2 , according to the directory to judge, add Expires function 7

Nine, compression configuration: 7

ix. Configuring load Balancing 9

first, the introduction of common Web server

Apache: Full-featured, long history

Cons: Processing each PHP comparison resource causes the server resource to be too expensive to process more requests if the concurrency is high.

Nginx : save resources, save CPU, so in high concurrency can handle more requests, high-end can reach 30,000 to 50,000 of the concurrency. Second, the Nginx understanding

Nginx ("Engine X") is a high-performance HTTP and reverse proxy server written by the Russians. Nginx is a good alternative to Apache server, it can support up to 50,000 concurrent connection number of responses, and memory, CPU and other system resource consumption is very low, running very stable.

In China, there have been Sina blog, Sina Podcast, NetEase News, six rooms, 56.com.discuz! official forum, water and wood community, watercress, domestic SNS, thunder online and many other websites using Nginx as a Web server or reverse proxy server. three, Nginx features

1 , it can be high concurrent connection , the official test can support 50,000 concurrent connections, in the actual production environment can support 2 to 40,000 concurrent connections.

2 , low memory consumption

nginx+php (FastCGI) server 30,000 concurrent connection, open 10 Nginx process consumes 150MB memory (15MB*10=150MB) Open 64 php-cgi process consumes 1280MB of memory (20MB*64=1280MB)

3 , low cost

Buying F5 big-IP, NetScaler and other hardware load balancing switches requires more than 100,000 or even hundreds of thousands of yuan. Nginx is open source software and can be used for a free trial and for commercial use.

4. Other reasons:

(1) configuration file is very simple: easy to understand, even if the non-professional administrator can read.

(2) Support rewrite rewrite rule: According to the different domain name, URL, the HTTP request to different back-end server groups.

(3) Built-in health check function: If the Nginx proxy backend server is down, it will not affect the front-end access.

(4) Save bandwidth, support gzip compression.

(5) High Stability: For reverse proxy, the probability of downtime is negligible.

(6) Support hot deployment. In the case of uninterrupted service, upgrade the software version. Iv. Supported operating systems:

FreeBSD 3.x,4.x,5.x,6.x i386; FreeBSD 5.x,6.x AMD64;

Linux 2.2,2.4,2.6 i386; Linux 2.6 amd64;

Solaris 8 i386; Solaris 9 i386 and sun4u; Solaris Ten i386;

MacOS X (10.4) PPC;

Windows Xp,windows Server 2003 and Windows 7, and so on. Five, installation of Nginx

1, download the software, unzip, copy to the specified directory

2, in cmd mode, into the nginx below to perform the start Nginx open Nginx Service

3, the IP address of the browser output server, to access.

A few operational commands:

Start Nginx to open Nginx service

Nginx–s Reload Reload the configuration file without shutting down the service

Nginx–s Stop Nginx service vi. Configuring a virtual host

Each server segment is a configured virtual host

server {

Specific configuration Items

Each line ends with a semicolon;

}

Domain-based virtual hosting:

After adding a file in the ABC directory, modify the local hosts file to access it.

Port-based virtual hosts:

Seven, nginx support PHP

Inside Apache PHP is launched as an Apache module.

In Nginx, PHP is started as a standalone process.

When a PHP file is encountered in Nginx, it is given to the PHP process to handle,

1, copy the PHP program files to the specified directory general and Nginx is the same level directory

2, the PHP program files to configure.

Open the PHP program directory and modify a copy of the php.ini file.

Modify the file to php.ini file

3, configure the PHP load extension library configuration

4. Configure PHP to start independently as a process.

5. Copy the three files to the Nginx directory.

Start_nginx.bat the script file is to start the PHP standalone process and Nginx

Stop_nginx.bat stops the ph independent process and nginx.

Configure the Start_nginx.bat file to match the directory installed in PHP.

6, modify the nginx.conf configuration file, open the support of PHP

After the configuration is complete, double-click the Start_nginx.bat file directly. Can. Eight, configure Nginx expires cache function 1, the overall configuration validity period:

For pictures, Css,js and other elements change less opportunities, especially the picture, you can set the picture in the browser local cache for 365 days, CSS,JS cache 10 days, this can improve the next time to open the user page loading speed, and save a lot of bandwidth. This feature is similar to Apache's expires. Here, with the function of location, the extension that needs to be cached is listed, and then the cache time is specified:

Location ~.*\. (gif|jpg|jpeg|png|bmp) $

{

Expires 365d;

}

2, according to the directory to judge, add expires function

Location ~ ^/(js|css|) / {

Expires 360d;

}

Nine, compression configuration:

gzip on;

#开启gzip压缩功能

Gzip_min_length 1k;

#设置允许压缩的页面最小字节数, the number of page bytes is obtained from the header content-length. The default value is 0, regardless of how much of the page is compressed. The recommended setting is greater than 1k. If less than 1k, it may be more pressing.

Gzip_buffers 4 16k;

#压缩缓冲区大小. Represents a request for 4 units of 16k of content as a compressed result stream cache, the default is to request the same amount of memory space as the original data to store gzip compression results.

Gzip_http_version 1.0;

#压缩版本 (default 1.1, 1.0 when the front end is squid2.5) is used to set the recognition HTTP protocol version, the default is 1.1, most browsers already support Gzip decompression, using the default.

Gzip_comp_level 2;

#压缩比率. Used to specify gzip compression ratio, 1 compression proportion small, processing speed, 9 compression proportion large, fast transmission speed, but the slowest processing, will also consume CPU resources.

Gzip_types text/plain application/x-javascript text/css application/xml;

#用来指定压缩的类型, the "text/html" type is always compressed.

Gzip_vary on;

#vary header support. This option allows the front-end cache server to cache gzip-compressed pages, such as using squid to cache nginx-compressed data.

Note: Objects that require and do not need to be compressed

(1) A plain text file greater than 1k html,js,css,xml,html.

(2) picture, video, etc. do not compress, because not only will not reduce, in compression consumes CPU and memory resources.

gzip on;

Gzip_min_length 1k;

Gzip_buffers 4 16k;

Gzip_http_version 1.0;

Gzip_comp_level 2;

Gzip_types text/plain application/x-javascript text/css application/xml;

Gzip_vary on;

Before compressing:

After compression:

Nine, configure load Balancing

Steps to start the configuration:

1. Establish two port-based virtual hosts and create corresponding files according to the directory.

2. Create a connection pool

Upstream the name of the connection pool {

Server www.123.com:81;

Server www.123.com:82;

}

3, the specific configuration, virtual host

4, in the Hosts file configuration of the domain name corresponding IP address, direct access can be.

20150410--lnmp+nginx-02

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.