LNMP environment setup-Nginx, lnmp build nginx

Source: Internet
Author: User
Tags openssl library nginx load balancing

LNMP environment setup-Nginx, lnmp build nginx

1. Nginx configuration file test

root@kallen:/usr/local/nginx/sbin# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

2. Start Nginx

[root@kallen ~]# /usr/local/nginx/sbin/nginx 

3. Nginx Load Balancing

Nginx Architecture:

Nginx LoadBalance:

Nginx High Availability:

Nginx upstream currently supports four allocation methods --

(1) Round Robin (default ):

Each request is distributed to different backend servers one by one in chronological order. If the backend servers are down, they can be removed automatically.

(2) weight:

Specify the round-robin probability. weight is proportional to the access ratio, which is used when the backend server performance is uneven.

(3) ip_hash:

Each request is allocated according to the hash result of the access ip address, so that each visitor accesses a backend server at a fixed time, which can solve the session problem. You can select the same backend server for the client in the same class C address segment unless the backend server is down.

(4) fair (third party ):

Requests are allocated based on the response time of the backend server. Requests with short response time are prioritized.

(5) url_hash (third-party ):

Requests are allocated based on the hash result of the access url so that each url is directed to the same backend server. The backend server is effective when it is cached.

4. Nginx installation and configuration

(1) install nginx source code

[root@kallen ~]# cd /usr/local/src/
[root@kallen ~]# wget http://syslab.comsenz.com/downloads/linux/nginx-0.9.6.tar.gz[root@kallen ~]# tar zxvf nginx-0.9.6.tar.gz[root@kallen ~]# cd nginx-0.9.6
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log --pid-path=/usr/local/nginx/var/nginx.pid --lock-path=/usr/local/nginx/var/nginx.lock --http-client-body-temp-path=/dev/shm/nginx_temp/client_body --http-proxy-temp-path=/dev/shm/nginx_temp/proxy --http-fastcgi-temp-path=/dev/shm/nginx_temp/fastcgi --user=www --group=www --with-cpu-opt=pentium4F --without-select_module --without-poll_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --without-http_ssi_module --without-http_userid_module --without-http_geo_module --without-http_memcached_module --without-http_map_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-pcre=/usr/local/src/pcre-8.32/ --with-zlib=/usr/local/zlib
[root@kallen ~]# make && make install [root@kallen ~]# mkdir /dev/shm/nginx_temp

Some nginx versions cannot be compiled due to pcre, so you need to modify it.
--with-pcre=/usr/local/src/pcre-8.32The above mentioned is that the pcresource code package pcre-7.8.tar.gz has been downloaded and decompressed/usr/local/src/pcre-8.32, No need to compile pcre.

In the actual installation process, you may need to manually install the following dependency packages:

A. Install dependent Software

apt-get --install-suggests install gcc g++ make

B. Download related software

wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gzwget http://zlib.net/zlib-1.2.8.tar.gzwget http://www.openssl.org/source/openssl-1.0.1g.tar.gzwget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2wget http://tengine.taobao.org/download/tengine-2.0.2.tar.gz

C. Install Pcre

  tar zxvf pcre-8.35.tar.gz  cd pcre-8.35 ./configure --prefix=/usr/local/pcre-8.35  make && make install

D. Install Zlib

  tar zxvf zlib-1.2.8.tar.gz  cd zlib-1.2.8  ./configure --prefix=/usr/local/zlib-1.2.8  make && make install

[ERROR]-1:

./configure: error: the HTTP gzip module requires the zlib library. You can either disable the module by using --without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using --with-zlib=<path> opti

[ERROR]-2:

configure: error: You need a C++ compiler for C++ support.make[1]: *** [/usr/local/src/pcre-8.32/Makefile] Error 1make[1]: Leaving directory `/home/kallen/MyDOC/nginx-1.8.0'make: *** [build] Error 2

The configuration information after installation is as follows:

[Nginx Configuration Summary]Configuration summary+ using PCRE library: /usr/local/src/pcre-8.32+ OpenSSL library is not used+using builtin md5 code+ sha1 library is not found+ using zlib library: /usr/local/zlib  nginx path prefix:"/usr/local/nginx"  nginx binary file:"/usr/local/nginx/sbin/nginx"  nginx configuration prefix:"/usr/local/nginx/conf"  nginx configuration file:"/usr/local/nginx/conf/nginx.conf"  nginx pid file:"/usr/local/nginx/var/nginx.pid"  nginx error log file:"/usr/local/nginx/logs/error.log"  nginx http access log file:"/usr/local/nginx/logs/access.log"  nginx http client request body temporary files:"/dev/shm/nginx_temp/client_body"  nginx http proxy temporary files:"/dev/shm/nginx_temp/proxy"  nginx http fastcgi temporary files:"/dev/shm/nginx_temp/fastcgi"  nginx http uwsgi temporary files:"uwsgi_temp"  nginx http scgi temporary files:"scgi_temp"

(2) Compile the nginx Startup Script

[root@kallen init.d]# vi /etc/init.d/nginx

Write the following content:

#!/bin/bash#        # Startup script for the Nginx HTTP Server## Kallen Ding, Apr 23 2015NGINX_PATH="/usr/local/nginx/"OPTIONS="-c ${NGINX_PATH}conf/nginx.conf"prog=nginxnginx=${NGINX_PATH}sbin/nginxpidfile=/var/run/nginx.pid# Source function library.. /etc/rc.d/init.d/functionsstart() {    echo -n "Starting $prog: "    daemon --pidfile=${pidfile} $nginx $OPTIONS    RETVAL=$?    echo    return $RETVAL}stop() {    echo -n "Stopping $prog: "    killproc -p ${pidfile} $nginx    RETVAL=$?    echo}reload() {    echo -n $"Reloading $prog: "    killproc -p ${pidfile} $nginx -HUP    RETVAL=$?    echo}# See how we were called.case "$1" in  start)    start    ;;  stop)    stop    ;;  restart)    stop    start    ;;  reload)        reload    ;;  status)    status $prog    RETVAL=$?    ;;  *)    echo "Usage: $prog {start|stop|restart|reload|status}"    RETVAL=3esacexit $RETVAL

Save and change/etc/init.d/nginxPermissions

[root@kallen ~]# chmod 755 /etc/init.d/nginx[root@kallen ~]# chkconfig --add nginx[root@kallen ~]# chkconfig nginx on

Note] All images in the text are fromOfficial Nginx website.

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.