码迷,mamicode.com
首页 > 其他好文 > 详细

CentOS 7 上搭建nginx 1.6

时间:2018-06-16 01:07:15      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:bmp   图片格式   51cto   周期性   centos 7   lis   list   XA   /usr   

准备要素,编译环境,创建组,创建被service所管理的脚本,两种隐藏版本方法,实现主进程用root创建 子进程有nginx 创建,图片缓存时间

在最新的centos7.3上搭建nginx 1.6.
安装需要的环境
yum install gcc gcc-c++ pcre-devel zlib-devel -y
yum install elinks -y 
创建用户组
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
cd /opt/nginx-1.6.0  //准备编译
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module

make && make install  //这个先不着急隐藏版本两种办法 这是第一种
隐藏版本信息在make 之前可以进行篡改 在解压的目录里面如我的解压在opt下路径 vim/opt/nginx-1.6.0/src/core/nginx.h 
#define nginx_version      1006000
#define NGINX_VERSION      "1.6.0" //修改双引号里面的字符串如 "1.1.1.1"

在make 之前窜改版本
技术分享图片

1、firewalld的基本使用
启动: systemctl start firewalld
查看状态: systemctl status firewalld 
停止: systemctl disable firewalld
禁用: systemctl stop firewalld

2.systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。
启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service
重启一个服务:systemctl restart firewalld.service
显示一个服务的状态:systemctl status firewalld.service
在开机时启用一个服务:systemctl enable firewalld.service
在开机时禁用一个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed

技术分享图片

yum install elinks -y  //用于字符界面测试nginx 
elinks http://IP地址/ 测试

第二种隐藏版本的方法就是在安装后修改nginx 主配置文件

vim /usr/local/nginx/conf/nginx.conf //主配置文件里面找到 
http {
    include       mime.types;
    default_type  application/octet-stream;
    server_tokens off; //插入这段话
#重启服务 先stop 在start  用curl -I http:// IP/
就会显示 
HTTP/1.1 200 OK
Server: nginx  //看个人需求
Date: Fri, 15 Jun 2018 14:59:07 GMT

修改用户和组 ps aux | grep nginx 查看进程
技术分享图片

vim /usr/local/nginx/conf/nginx.conf //修改主配置文件
user  nginx nginx; //就在开头 #号注释掉 换成nginx 
location / {
            root   html;
            index  index.html index.htm;
        } //在下面插入
location ~\.(gif|jpg|jepg|png|bmp|ico)$ {
            root html; //支持的图片格式
            expires 1d; //静态图片缓存为一天
        }
重启服务 使用抓包工具进行查看

修改首页 vim/usr/local/nginx/html/index.html

<h1>Welcome to nginx!</h1> //显示首页标题
<img src="game.jpg">  //图片路径
重启服务 别忘把图片复制到 index.html 同一个目录里

技术分享图片
链接超时

vim /usr/local/nginx/conf/nginx.conf //默认已经就是开启的 找到keepalive_timeout 修改 单位秒
keepalive_timeout  65 180; //65 超时时间 180客户超时时间
client_header_timeout 80; // 请求头部的超时时间
client_body_timeout 80; // 读写内容超时时间 
重启服务 

日志分割 要创建脚本并且写入到周期性计划任务里

#!/bin/bash
#Filename:fenge.sh
d=$(date -d "-1 day" "+%Y%m%d")    #显示一天前的时间
logs_path="/var/log/nginx" #日志分隔出来的保存路径
pid_path="/usr/local/nginx/logs/nginx.pid" #日志进程序列号
[ -d $logs_path ] || mkdir -p $logs_path # 判断有没有保存路径文件存在 若没有则创建并以前一天年月日的形式
mv /usr/local/nginx/logs/access.log #剪切移动访问日志 移动到保存前面备份准备的路径并且以前一天日期结尾 ${logs_path}/test.com-access.log-$d
kill -USR1 $(cat $pid_path) #杀死进程 则会重新生成新的日志文件
find $logs_path -mtime +30 | xargs rm -rf # 当存储到达30 时 则会删除前30 天的备份文件

技术分享图片
技术分享图片

CentOS 7 上搭建nginx 1.6

标签:bmp   图片格式   51cto   周期性   centos 7   lis   list   XA   /usr   

原文地址:http://blog.51cto.com/13660858/2129990

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!