nginx 下载:
http://nginx.org/en/download.html
Nginx的版本有:
Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以说是开发版。
Stable version:最新稳定版,生产环境上建议使用的版本。
Legacy versions:遗留的老版本的稳定版。
一般就选最新版本,Stable version:最新稳定版。
ngixn安装:
http://nginx.org/download/nginx-1.20.0.tar.gz
①.安装如下3个依赖软件:
yum -y install pcre pcre-devel
yum -y install openssl openssl-devel
yum -y install zlib zlib-devel
?
? ②.上传文件/解压文件/ 安装为服务
tar -zxvf nginx-1.20.0.tar.gz
cd nginx-1.20.0
./configure --prefix=/usr/local/nginx --with-http_ssl_module
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
make && make install
make[1]: 离开目录“/root/test/nginx-1.20.0”
③.启动nginx (安装的文件)
/usr/local/nginx/sbin/nginx
参数 "-c" 指定了配置文件的路径,如果不加 "-c" 参数,Nginx 会默认加载其安装目录的 conf 子目录中的 nginx.conf 文件。
检查是否启动
netstat -tunpl | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 5410/nginx: master
## 没有添加path 用绝对路径
nginx –s stop 停止nginx的服务
nginx –s reload 不停止nginx的服务,重新加载配置文件。
nginx –t 检测配置文件是否有错误。
④. 外界访问/防火墙开放端口
firewall-cmd --zone=public --list-ports # 查看开放端口
firewall-cmd --zone=public --add-port=80/tcp --permanent # 开启端口
firewall-cmd --reload # 重启防火墙
? 浏览器 输入 linux 服务器 ip 地址即可
nginx 修改日志配置:
① 进入配置文件
/usr/local/nginx/conf
vim nginx.conf
? ② 日志配置
在http 断定义格式{
log_format mylog ‘$remote_addr - $request - $status - $http_user_agent - $http_referer‘;
}
在server 指定目录 server {
access_log logs/nihao.log mylog;
}
重启 : /usr/local/nginx/sbin/nginx -s reload
浏览器访问ngix/进入log查看日志文件
cd /usr/local/nginx/logs
nginx 定时任务,完成日志分割:
? ① 编写sh脚本
在/date目录下面新建一个脚本runlog.sh
mkdir /date
vim runlog.sh
#!/bin/bash
logname=/usr/local/nginx/logs/nihao.log
newlog=/date/$(date -d yesterday +%Y%m%d%H%M).nihao.log
mv $logname $newlog
touch $logname
kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
? ② 编写定时任务 运行① sh脚本
crontab -e
*/1 * * * * sh /date/runlog.sh
查看定时任务crontab -l
编辑定时任务crontab –e
删除定时任务crontab -r
注:如果没有安装定时任务,可以使用
yum install -y vixie-cron 命令进行安装;
启动定时任务 service crond start
原文:https://www.cnblogs.com/xfych/p/14790551.html