Linux Course notes Nginx Introduction

Source: Internet
Author: User

1 Nginx Introduction

Compared with Apache, in performance, Nginx occupies less system resources, the specific scene application (static data) can support more concurrent connections, achieve higher access efficiency; in function, Nginx is an excellent reverse proxy and load Balancer server, also can be used as a cache server.

2 Nginx a little summary:

    1. High concurrency: Capable of supporting 120,000 or more concurrent connections (static small file environment)
    2. Low memory consumption: up to 30,000 concurrent connections, 10 nginx processes open consume less than 200M of memory
    3. Can do HTTP reverse proxy, that is, load balancing function, equivalent to professional haproxy software or LVS function
    4. Built-in to the RS server Health Check function: If the Nginx agent back end of a Web server down, will not affect the front-end access, this function is relatively weak, need to be improved.
    5. The cache plug-in can be implemented like squid and other professional caching software implementation functions

The main advantages of Nginx are: Support Kqueue (FreeBSD 4.1+), Epoll (Linux 2.6+) and other network IO event models, thereby supporting high-concurrency connections. Apache supports the Select model.

3 Nginx's main application scenarios

Web server

1) combine fastcgi to run PHP, JSP and other programs

2) Run html,js,css, small pictures and other static data

Proxy Server

1) Do reverse proxy or load balancing, rule filtering

Cache server

2) Add cache plugin for Web server caching function

4 Mainstream Server Product comparison

Apache

(1) 2.2 version is very powerful, the official note, 2.4 version of the performance is very strong

(2) Perfork mode cancels process creation overhead, high performance

(3) When dealing with dynamic business data, the bottleneck is not the Apache itself, due to the engine and database associated with the backend.

(4) High concurrent consumption system resources are relatively more

Nginx

(1) based on asynchronous IO model, strong performance, can support tens of thousands of concurrent

(2) Support for small files is very good, high performance (limited to static small files)

(3) Beautiful code. Extensions must be programmed into the main process

(4) Low consumption system resources

5 Why Nginx Overall performance is higher than Apache

6 Nginx Base Installation

6.1 Pcre Installation

Pcre, Chinese-compatible regular expression, install Pcre Library is to enable Nginx support HTTP rewrite module

wget http://exim.mirror.fr/pcre/pcre-8.30.tar.gz

Tar zxf pcre-8.30.tar.gz

CD pcre-8.30

./configure

Make && make install

Note: "libtool:compile:unrecognized option '-dhave_config_h" was encountered during the installation process. This is because gcc-c++ is not installed. Yum install gcc-c++ can be solved.

6.2 Nginx Installation

wget http://nginx.org/download/nginx-1.2.9.tar.gz

Useradd nginx-s/sbin/nologin-m #创建nginx这个用户, can be arbitrarily named

Tar zxf nginx-1.2.9.tar.gz

CD nginx-1.2.9

./configure--user=nginx--group=nginx--prefix=/application/nginx-1.2.9--with-http_stub_status_module--with-http _ssl_module

Make && make install

Ln-s/application/nginx-1.2.9/application/nginx #在版本升级的时候很重要

./configure after parameter description: (more available with./configure--help query)

--user=user set non-privileged user for

--group=group set non-privileged Group for

--with-http_stub_status_module Enable Ngx_http_stub_status_module

--with-http_ssl_module Enable Ngx_http_ssl_module

6.3 Nginx Start-up

[Email protected] nginx-1.2.9]#/application/nginx/sbin/nginx

/application/nginx/sbin/nginx:error while loading shared libraries:libpcre.so.1:cannot open shared object File:no such File or directory

#这是由于libpcre. so.1 file cannot be found, this error does not occur if Yum is installed

[[email protected] nginx-1.2.9]# Find/-type f-name "libpcre.so.*"

/lib64/libpcre.so.0.0.1

/usr/local/lib/libpcre.so.1.0.0

/root/tools/pcre-8.30/.libs/libpcre.so.1.0.0

[Email protected] nginx-1.2.9]# vi/etc/ld.so.conf

Include ld.so.conf.d/*.conf

/usr/local/lib/

[Email protected] nginx-1.2.9]# Ldconfig #使配置文件生效

[Email protected] nginx-1.2.9]#/application/nginx/sbin/nginx-t

Nginx:the configuration file/application/nginx-1.2.9/conf/nginx.conf syntax is OK

Nginx:configuration file/application/nginx-1.2.9/conf/nginx.conf Test is successful

Verify Startup:

[Email protected] nginx-1.2.9]# lsof-i:80

COMMAND PID USER FD TYPE DEVICE size/off NODE NAME

Nginx 16853 root 6u IPv4 34743 0t0 TCP *:http (LISTEN)

Nginx 16854 nginx 6u IPv4 34743 0t0 TCP *:http (LISTEN)

Difficult questions:

[Email protected] nginx-1.2.9]#/application/nginx/sbin/nginx

Nginx: [Emerg] Getpwnam ("Nginx") failed

#这是由于没有创建用户导致的, it only takes Userdel nginx to reproduce the problem.

6.4 Nginx configuration file

Worker_processes 1;

Events {

Worker_connections 1024;

}

HTTP {

Include Mime.types;

Default_type Application/octet-stream;

Sendfile on;

Keepalive_timeout 65;

server {

Listen 80;

server_name localhost;

Location/{

root HTML;

Index index.html index.htm;

}

Error_page 502 503 504/50x.html;

Location =/50x.html {

root HTML;

}

}

}

Linux Course note nginx Introduction

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.