###安装
yum install -y pcre zlib openssl jemallocid
groupadd www-data
useradd -s /sbin/nologin -g www-data www-data
cd /tmp
wget http://tengine.taobao.org/download/tengine-2.3.3.tar.gz
tar -zxvf tengine-2.3.3.tar.gz
cd tengine-2.3.3
./configure --prefix=/usr/local/tengine-2.3.3 --user=www-data --group=www-data --with-threads --with-http_v2_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_stub_status_module --add-module=modules/ngx_http_upstream_session_sticky_module --add-module=modules/ngx_http_upstream_check_module --with-stream --with-stream_ssl_module
make
make install
###配置服务
cd /usr/local/
ln -s tengine-2.3.3 nginx
vim /lib/systemd/system/nginx.service #加入以下内容
[Unit]
Description=The nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
Execstop=/bin/kill -s QUIT $SMAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#保存并使之生效
systemctl daemon-reload
###配置tengine
mkdir /usr/local/tengine-2.3.3/vhosts
cp -a /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.original
vim /usr/local/nginx/conf/nginx.conf
user www-data;
worker_processes auto;
pid logs/nginx.pid;
events{
accept_mutex on;
multi_accept on;
worker_connections 65535;
}
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"';
log_format hr_upstreams '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer"'
'"$http_user_agent" "$http_x_forwarded_for" $request_time $upstream_response_time "$upstream_addr" $upstream_status';
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log warn;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
gzip_disable "msie6";
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_vary on;
gzip_http_version 1.1;
gzip_types text/plain text/css text/xml text/javascript application/json application/x-javascript application/xml application/xml+rss;
charset UTF-8;
include /usr/local/nginx/vhosts/*.conf;
server{
listen 80 default;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html{
root html;
}
}
}
mkdir -p /var/log/nginx
chown -R www-data. /var/log/nginx
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx
###检查与开启
nginx -t
systemctl start nginx