您的位置:首页 > 运维架构 > Nginx

Nginx 安装配置 禁止使用IP访问 rewrite重写 别名设置 日志轮询

2015-08-15 15:31 1036 查看


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-pcre

5、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.conf
worker_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/sh
logPath="/application/nginx/logs/" #定义存放日志的目录变量

cd $logPath
mv access.log access_$(date +%F).log
/application/nginx/sbin/nginx -s reload
find /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


本文出自 “肖海” 博客,请务必保留此出处http://eveday.blog.51cto.com/10577430/1684860
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: