Nginx configuration based on Memcached cache Web Server

Source: Internet
Author: User

I. Configure the environment

Linux: CentOS 6.5 64bit

Nginx: nginx-1.4.7

Php: php-5.4.26

Mysql: mysql-5.5.33

Xcache: xcache-3.1.0

Memcached: memcached-1.4.4-3.el6.x86_64

Memcached PHP extended: memcache-2.2.7

Refer:

Memcached installation and startup script

Performance problems of using Memcached in PHP

Install Memcached in Ubuntu and its command explanation

Install and apply Memcached

Use Nginx + Memcached's small image storage solution

Getting started with Memcached

Ii. Install nginx

Nginx is a web server software with market share second only to httpd. It supports reverse proxy, simple load balancing, fault tolerance, outstanding performance, and modular structure. Therefore, you can configure web servers, nginx is a good choice;

1. Resolve dependencies before installation

# Yum-y groupinstall "Development Tools"

# Yum-y install pcre-devel openssl-devel

 

2. Install nginx

# Useradd-r nginx

# Tar xf nginx-1.4.7.tar.gz

# Cd nginx-1.4.7

#./Configure \

-- Prefix =/usr/local/nginx \

-- Sbin-path =/usr/local/nginx/sbin/nginx \

-- Conf-path =/etc/nginx. conf \

-- Error-log-path =/var/log/nginx/error. log \

-- Http-log-path =/var/log/nginx/access. log \

-- Pid-path =/var/run/nginx. pid \

-- Lock-path =/var/lock/nginx. lock \

-- User = nginx \

-- Group = nginx \

With-http_ssl_module \

With-http_flv_module \

With-http_stub_status_module \

With-http_gzip_static_module \

-- Http-client-body-temp-path =/var/tmp/nginx/client /\

-- Http-proxy-temp-path =/var/tmp/nginx/proxy /\

-- Http-fastcgi-temp-path =/var/tmp/nginx/fcgi /\

-- Http-uwsgi-temp-path =/var/tmp/nginx/uwsgi \

-- Http-scgi-temp-path =/var/tmp/nginx/scgi \

-- With-pcre

# Make & make install

 

3. Provide Service server scripts

# Vim/etc/rc. d/init. d/nginx

The content is as follows:

#! /Bin/sh

#

# Nginx-this script starts and stops the nginx daemon

#

# Chkconfig:-85 15

# Description: Nginx is an HTTP (S) server, HTTP (S) reverse \

# Proxy and IMAP/POP3 proxy server

# Processname: nginx

# Config:/etc/nginx. conf

# Config:/etc/sysconfig/nginx

# Pidfile:/var/run/nginx. pid

 

# Source function library.

./Etc/rc. d/init. d/functions

 

# Source networking configuration.

./Etc/sysconfig/network

 

# Check that networking is up.

["$ NETWORKING" = "no"] & exit 0

 

Nginx = "/usr/local/nginx/sbin/nginx"

Prog = $ (basename $ nginx)

 

NGINX_CONF_FILE = "/etc/nginx. conf"

 

[-F/etc/sysconfig/nginx] &./etc/sysconfig/nginx

 

Lockfile =/var/lock/subsys/nginx

 

Make_dirs (){

# Make required directories

User = 'nginx-V 2> & 1 | grep "configure arguments:" | sed's/[^ *] * -- user = \ ([^] * \). */\ 1/G '-'

Options = '$ nginx-V 2> & 1 | grep' configure arguments :''

For opt in $ options; do

If ['echo $ opt | grep'. *-temp-path'']; then

Value = 'echo $ opt | cut-d "="-f 2'

If [! -D "$ value"]; then

# Echo "creating" $ value

Mkdir-p $ value & chown-R $ user $ value

Fi

Fi

Done

}

 

Start (){

[-X $ nginx] | exit 5

[-F $ NGINX_CONF_FILE] | exit 6

Make_dirs

Echo-n $ "Starting $ prog :"

Daemon $ nginx-c $ NGINX_CONF_FILE

Retval =$?

Echo

[$ Retval-eq 0] & touch $ lockfile

Return $ retval

}

 

Stop (){

Echo-n $ "Stopping $ prog :"

Killproc $ prog-QUIT

Retval =$?

Echo

[$ Retval-eq 0] & rm-f $ lockfile

Return $ retval

}

 

Restart (){

Configtest | return $?

Stop

Sleep 1

Start

}

 

Reload (){

Configtest | return $?

Echo-n $ "Reloading $ prog :"

Killproc $ nginx-HUP

RETVAL =$?

Echo

}

 

Force_reload (){

Restart

}

 

Configtest (){

$ Nginx-t-c $ NGINX_CONF_FILE

}

 

Rh_status (){

Status $ prog

}

 

Rh_status_q (){

Rh_status>/dev/null 2> & 1

}

 

Case "$1" in

Start)

Rh_status_q & exit 0

$1

;;

Stop)

Rh_status_q | exit 0

$1

;;

Restart | configtest)

$1

;;

Reload)

Rh_status_q | exit 7

$1

;;

Force-reload)

Force_reload

;;

Status)

Rh_status

;;

Condrestart | try-restart)

Rh_status_q | exit 0

;;

*)

Echo $ "Usage: $0 {start | stop | status | restart | condrestart | try-restart | reload | force-reload | configtest }"

Exit 2

Esac

 

Add the execution permission to the script:

# Chmod + x/etc/rc. d/init. d/nginx

 

Start the service:

# Service nginx star

 

 

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • 3
  • 4
  • Next Page

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.