LNMP Environment Construction--nginx Chapter

Source: Internet
Author: User

1.Nginx configuration file Test

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

2.Nginx Boot

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

3.Nginx Load Balancing

Nginx's upstream currently supports 4 different ways of distribution--

(1) Polling (default):

Each request is assigned to a different back-end server in chronological order, and can be automatically rejected if the backend server is down.

(2) Weight:

Specifies the polling probability, proportional to the weight and access ratios, for situations where the performance of the backend server is uneven.

(3) Ip_hash:

Each request is allocated according to the hash result of the access IP, so that each visitor has fixed access to a back-end server that resolves the session issue. You can select the same back-end server for clients in the same Class C address segment, unless that backend server is down for another one.

(4) Fair (third party):

The response time of the back-end server is allocated to the request, and the response time is short of priority allocation.

(5) Url_hash (third party):

Assign requests by the hash result of the access URL so that each URL is directed to the same back-end server, which is more efficient when the backend server is cached.

4.Nginx Installation and Configuration

(1) Nginx source installation

[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 of the Nginx version will be compiled because the Pcre compilation does not pass, need to modify
--with-pcre=/usr/local/src/pcre-8.32, the premise is already downloaded Pcre source package pcre-7.8.tar.gz, and extracted to /usr/local/src/pcre-8.32 , do not need to compile pcre.

You may need to manually install the following dependency packages during the actual installation process:

A. Installing dependent software

apt-get--install-suggestsinstallgccg++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. Installing Pcre

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

D. Installing 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:

thethethebyusing--without-http_gzip_module ortheintothesystemorthefromthewithbyusing--with-zlib=
   
    
     
     opti
   
    

[Error]-2:

configure: error: You need a C++ compiler for C+`/home/kallen/MyDOC/nginx-1.8.0'make: *** [build] Error 2

The configuration information after the installation is complete is as follows:

[NginxConfigurationSummary]Configurationsummary+ using PCRELibrary:/usr/local/src/pcre-8.32+ OpenSSLLibrary is notUsed+using Builtin MD5 code+ SHA1Library is notFound+ using zlibLibrary:/usr/local/zlib nginx Path prefix:"/usr/local/nginx"Nginx Binaryfile:"/usr/local/nginx/sbin/nginx"NginxConfigurationPrefix"/usr/local/nginx/conf"NginxConfigurationfile:"/usr/local/nginx/conf/nginx.conf"Nginx PIDfile:"/usr/local/nginx/var/nginx.pid"Nginx error Logfile:"/usr/local/nginx/logs/error.log"Nginx httpAccessLogfile:"/usr/local/nginx/logs/access.log"Nginx HTTP Client RequestBodyTemporary 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) Writing 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, APRNginx_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$OPTIONSRetval=$?Echoreturn$RETVAL}Stop() {Echo-N"Stopping $prog:"Killproc-p${pidfile}$nginxRetval=$?Echo}Reload() {Echo-N $"Reloading $prog:"Killproc-p${pidfile}$nginx-hup retval=$?Echo}# See how we were called. Case"$"inchStart) Start;  stop) stop;;  restart) stop start;;  reload) reload;; Status) status$progRetval=$?  ;; *)Echo"Usage: $prog {start|stop|restart|reload|status}"Retval=3EsacExit$RETVAL

After saving, change /etc/init.d/nginx the permissions

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

The above describes the LNMP environment to build--nginx, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.