CentOS6.4 configuration Tengine (RPM)

Source: Internet
Author: User
Tags install openssl

1. Install the Pcre-devel library required by Nginx

Yum install-y gcc gcc-c++wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.gztar zxvf PCRE-8.33.TAR.GZCD pcre-8.33
./configure--prefix=/usr/local/pcremake
Make install

2, Installation Tengine

Yum install OpenSSL openssl-develwget Http://tengine.taobao.org/download/tengine-1.5.1.tar.gztar ZXVF TENGINE-1.5.1.TAR.GZCD tengine-1.5.1./configure--prefix=/usr/local/nginx--with-http_stub_status_module-- With-pcre=/usr/local/pcre-8.33makemake Install

Note:--with-pcre=/usr/local/software/pcre-8.33 Specifies the path of the source package decompression
3, Configuration Tengine

Create user groups and users

Groupadd wwwuseradd-g www www

Edit the master configuration file

Vi/usr/local/nginx/conf/nginx.conf

User www www;    #指定运行的用户和用户组worker_processes 4;        #指定要开启的进程数, generally the core number of CPUs or twice times error_log Logs/error.log Crit;      #全局日志 Debug|info|notice|warn|error|critpid Logs/nginx.pid;  #指定进程id的存储文件位置worker_rlimit_nofile 65535;events {use epoll;  #对于Linux系统epoll工作模式是首选 worker_connections 65536;    #每个进程的最大连接数 #在执行操作系统命令 "Ulimit-n 65536" after the worker_connections settings to take effect}http {include mime.types;    Default_type Application/octet-stream; Log_format Main ' $remote _addr-$remote _user [$time _local] "$request" "$status $body _bytes_sent"    $http _referer "'" $http _user_agent "" $http _x_forwarded_for ";    Access_log Logs/access.log Main;    CharSet Utf-8;    Server_names_hash_bucket_size 256;    Client_header_buffer_size 32k; Large_client_header_buffers 4 128k;   #最大缓存为4个128KB client_max_body_size 20m;        #允许客户端请求的最大的单个文件字节数 sendfile on;      #开启高效文件传输模式 Tcp_nopush on;     #用于防止网络阻塞 Tcp_nodelay on;    #用于防止网络阻塞Keepalive_timeout 60;   #超过这个时间之后服务器会关闭该连接 Client_header_timeout 10;     #客户端请求头读取超时时间, more than this time the client has not sent data Nginx returned 408 error client_body_timeout 10;   #客户端请求主体读取超时时间, more than this time the client has not sent data Nginx returned 408 error server_tokens on;  #不显示nginx版本信息 include gzip.conf; #HttpGzip的配置文件 include proxy.conf; #配置代理文件 include vhost.conf;       #虚拟主机的配置文件 include backend.conf; #配置后端的服务器列表文件}

Limit_req_zone $binary _remote_addr zone=req_one:10m rate=1r/s;
#10m是会话状态存储空间 rate=1r/s is only requested once per second (VHOST.CONF and configured)
Limit_conn_zone $binary _remote_addr zone=req_one:10m;
#设置IP并发 (also configured in vhost.conf)
Edit the Httpgzip configuration file

Vi/usr/local/nginx/conf/gzip.conf

gzip On;gzip_min_length 1k;     #设置允许压缩的页面最小字节数. Gzip_buffers 4 16k;     #用来存储gzip的压缩结果gzip_http_version 1.1;  #识别HTTP协议版本gzip_comp_level 2;      #设置gzip的压缩比 1-9 1 compression ratio of the smallest but fastest 9 contrary to gzip_types text/plain application/x-javascript text/css application/xml;        #指定压缩类型gzip_proxied any;       #无论后端服务器的headers头返回什么信息, all unconditionally enable compression gzip_vary on;gzip_disable "MSIE [1-6].";     #禁用IE6的gzip压缩

Edit Proxy file

Vi/usr/local/nginx/conf/proxy.conf

Proxy_redirect off;proxy_set_header Host $host;p roxy_set_header x-real-ip $remote _addr;proxy_set_header X-forwarded-for $proxy _add_x_forwarded_for;client_body_buffer_size  512k;proxy_connect_timeout 30;proxy_read_ Timeout 30;proxy_send_timeout 30;proxy_buffer_size 32k;proxy_buffers 4 64k;proxy_busy_buffers_size 128k;

Edit the configuration file for a virtual host

Vi/usr/local/nginx/conf/vhost.conf

server {    listen;    server_name localhost;    Index index.jsp index.htm index.html;    Root/usr/local/tomcat7/webapps/root;    Location/{
Proxy_pass Http://backend; Proxy_pass_header Set-cookie; } Location/nginxstatus { stub_status on; Access_log off; Auth_basic "Nginxstatus"; }}

Location ~. *\. (Zip|thumb) $ {
Root/usr/local/download;
Limit_conn Req_one 1; #IP下载并发为1 Req_one the Limit_conn_zone $binary _remote_addr zone=req_one:10m configured in the nginx.conf;
Limit_rate 500k; #限速500k
Expires 30d;
}

Limit_req Zone=req_one burst=100; #req_one在nginx. conf is configured, when the rate is exceeded the request will be placed in the burst burst is full 503 req_one in nginx.conf configuration Llimit_req_zone $binary _remote_ Addr zone=req_one:10m rate=100r/s;

Limit_rate_after 3m;
Limit_rate 512k; The meaning of these two words is to first download 3MB at the fastest speed, and then at 512KB speed download.

The static file with the extension zip,thumb is given to Nginx, root is the directory of the static file, and expires is used as the expiration time of the specified static file for 30 days.

Location ~ ^/(upload|download)/{
root/usr/local;
Expires 30d;
}

All files under Upload,download are given to Nginx, upload and download directories are included in the/usr/local directory.

Edit the server list file on the back end

Vi/usr/local/nginx/conf/backend.conf

Upstream backend {    ip_hash;    Server 127.0.0.1:8080 Max_fails=1 fail_timeout=60s;}

4, set Tengine boot

#!/bin/bash# tengine Startup script# processname:nginx# chkconfig:-15# Description:nginx is a world Wide Web server . It is used to serve# pidfile:/var/run/nginx.pid# config:/usr/local/nginx/conf/nginx.confnginxd=/usr/local/nginx/sbin /nginxnginx_config=/usr/local/nginx/conf/nginx.confnginx_pid=/usr/local/nginx/logs/nginx.pidretval=0prog= " Nginx "# Source function library. /etc/rc.d/init.d/functions# Source Networking configuration: /etc/sysconfig/network# Check that networking are up. [${networking} = "No"] && exit 0[-x $nginxd] | | Exit 0# Start Nginx daemons Functions.start () {If [-e $nginx _pid];thenecho "Tengine already running ...." Exit 1fiecho-n $ "Starting $prog:" Daemon $nginxd-c ${nginx_config}retval=$?echo[$RETVAL = 0] && touch/var/lock/subsys/nginxre Turn $RETVAL}# Stop nginx daemons functions.stop () {echo-n $ "stopping $prog:" Killproc $nginxdRETVAL =$?echo[$RETVAL = 0 ] && rm-f/var/lock/subsys/nginx/usr/local/nginx/logs/nginx.pid}reloAD () {echo-n $ "reloading $prog:" #kill-hup ' cat ${nginx_pid} ' Killproc $nginxd-hupretval=$?echo}# See how we were called . Case "$" instart) start; stop) stop;; reload) reload;; restart) Stopstart;; Status) status $progRETVAL =$?;; *) echo $ "Usage: $prog {start|stop|restart|reload|status|help}" exit 1esacexit $RETVAL

Save exit

chmod 775/etc/rc.d/init.d/nginx   #赋予文件执行权限chkconfig  --level 012345 nginx on   #设置开机启动
Service Nginx Start

5. Other

Original address: http://www.cnblogs.com/kgdxpr/p/3304747.html

CentOS6.4 configuration Tengine (RPM)

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.