1、yum install pcre pcre-devel -y
#支持rewrite重写功能2、yum -y install openssl openssl-devel
#支持https功能3、useradd nginx -s /sbin/nologin -M
#添加用户4、tar zxf nginx-1.6.2.tar.gz
cd nginx-1.6.2./configure \--user=nginx --group=nginx \--prefix=/application/nginx-1.6.2 \--with-http_stub_status_module \--with-http_ssl_module \--with-pcre5、make && make install
6、ln -s /application/nginx-1.6.2 /application/nginx
#做一个软链接7、/application/nginx/sbin/nginx -t
/application/nginx/sbin/nginx#检查并启动服务8、echo 'PATH="/application/nginx/sbin:$PATH"' >>/etc/profile
source /etc/profile#添加环境变量9、修改配置文件
[root@Nginx conf]# cat nginx.confworker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; 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;#禁止使用IP访问网站 server { listen 80; location / { return 404;} }#设置别名 server { listen 80; server_name www.cui.com cui.com; location / { root /data/www; index index.html index.htm; } }#301 rewrite地址重写 server { listen 80; server_name www.cui.org; rewrite ^/(.*)$ http://www.cui.com/$1 permanent; }}10、日志轮询
[root@Nginx scripts]# cat cut_nginx_log.sh #!/bin/shlogPath="/application/nginx/logs/" #定义存放日志的目录变量cd $logPathmv access.log access_$(date +%F).log/application/nginx/sbin/nginx -s reloadfind /application/nginx/logs/ -name access_*.log -mtime +7|xargs rm -f #保留7天的日志11、做定时任务
[root@Nginx scripts]# crontab -l|tail -2 ###########00 00 * * * /bin/sh /server/scripts/cut_nginx_log.sh >/dev/null 2>&1