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):
- 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
- 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.conf
Add the contents of the file as follows: [email protected] libevent]# Ldconfig
- Installing the Nginx process
Unzip and configure the Nginx package#tar –zxvf nginx-1.6.2.tar.gz
Generate 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=opteron
Compile#make
Installing Nginx#make install
Check that the Nginx configuration is correct#/usr/local/nginx/sbin/nginx -t
Start Nginx#/usr/local/nginx/sbin/nginx
View Nginx Boot Status#ps –ef|grep nginx
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; } }
Re-start Nginx Killall ngnix
#/usr/local/nginx/sbin/nginx
get ""
Teach you to know and build Nginx