Teach you to know and build Nginx

Source: Internet
Author: User

Teach you to know and build Nginx

Nginx ("Engine X") is a high-performance HTTP and reverse proxy server, also a IMAP/POP3/SMTP proxy server. Nginx was developed by Igor Sysoev, the second-most visited rambler.ru site in Russia, which has already run more than 2.5 of the site. Igor release the source code in the form of a BSD-like license. Although still beta, Nginx has been known for its stability, rich feature set, sample configuration files, and low system resource consumption.

First, the advantages of Nginx:

as a WEB server: using fewer resources compared to Apache,nginx, supporting more concurrent connections and increasing efficiency, this makes Nginx particularly popular with virtual hosting providers. Capable of supporting responses of up to 50,000 concurrent connections.

as a Load balancer server: Nginx can support both Rails and PHP internally, as well as HTTP proxy servers for external service. Nginx written in C, whether it is the system resource overhead or CPU use efficiency is much better than Perlbal.

as the Mail proxy server: Nginx is also a very good mail proxy server (one of the first to develop this product is also as a mail proxy server).

Nginx installation is very simple, the configuration file is very concise, bugs very few servers: Nginx boot is particularly easy, and can be almost uninterrupted operation, even if the operation for several months do not need to restart. You will also be able to upgrade your software version in the event of uninterrupted service.

Two. Install the Nginx process (build on CentOS):
  1. Installing Nginx-dependent plugins is recommended for online installation via Yum.
    yum -y install pcre-devel openssl openssl-devel gcc+c--Pcre-devel is a plug-in that supports read-write (a library that supports regular expressions), such as plugin OpenSSL, which supports SSL certificates
  2. Install Libevent (because Nginx uses the Epoll mechanism requires event library support)
    [[email protected]~]# tar -zxvf libevent-2.0.16-stable.tar.gz -C /usr/local/src/ [[email protected]~]# cd /usr/local/src/libevent-2.0.16-stable/ [[email protected] libevent-2.0.16-stable]# ./configure --prefix=/usr/local/libevent [[email protected] libevent-2.0.16-stable]# make && make install [[email protected] libevent-2.0.16-stable]# cd /usr/local/libevent/In order for the system to be able to invoke Libevent's header files and library files by other programs, we need to do the following:[[email protected] libevent]# ln -s /usr/local/libevent/include /usr/include/libevent [[email protected] libevent]# vim /etc/ld.so.conf.d/libevent.confAdd the contents of the file as follows: [email protected] libevent]# Ldconfig
  3. Installing the Nginx process
    Unzip and configure the Nginx package#tar –zxvf nginx-1.6.2.tar.gzGenerate a new directory nginx-1.6.2, enter the directory, configure the installation of Nginx required configuration information#./configure --user=root --group=root --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-cc-opt=‘-O2‘ --with-cpu-opt=opteronCompile#makeInstalling Nginx#make installCheck that the Nginx configuration is correct#/usr/local/nginx/sbin/nginx -tStart Nginx#/usr/local/nginx/sbin/nginxView Nginx Boot Status#ps –ef|grep nginx
  4. Here Nginx installation has been completed, the next add Nginx Proxy service

      user root;  #工作进程, worker_processes 2 is generally determined based on the number of CPU cores;     server {Listen 9457;     server_name localhost;         Location/{root HTML;     Index index.html index.htm;         } #这里配上项目地址的分发 location/yourproject1/{proxy_pass http://127.0.0.1:8080/YourProject1/;         Proxy_set_header Host $host;            Proxy_set_header x-forwarded-for $remote _addr;         } location/yourproject2/{Proxy_pass http://127.0.0.1:8090/YourProject2/;         Proxy_set_header Host $host;            Proxy_set_header x-forwarded-for $remote _addr; } }
  5. Re-start Nginx Killall ngnix#/usr/local/nginx/sbin/nginx


get ""

Teach you to know and build Nginx

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.