Nginx 安装配置 禁止使用IP访问 rewrite重写 别名设置 日志轮询
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Nginx 安装配置 禁止使用IP访问 rewrite重写 别名设置 日志轮询,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1935字,纯文字阅读大概需要3分钟。
内容图文
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
原文:http://eveday.blog.51cto.com/10577430/1684860
内容总结
以上是互联网集市为您收集整理的Nginx 安装配置 禁止使用IP访问 rewrite重写 别名设置 日志轮询全部内容,希望文章能够帮你解决Nginx 安装配置 禁止使用IP访问 rewrite重写 别名设置 日志轮询所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。