nginx的下载
2019-06-10 本文已影响0人
古巷挂青灯
1、基于官方源进行nginx安装:
第一个历程:系统环境进行调整
yum install -y gcc gcc-c++ autoconf pcre pcre-devel make automake wget httpd-tools vim tree
第二个历程:配置nginx的官方源
vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
第三个历程: 直接下载安装nginx程序
yum install nginx
第四个历程: 启动nginx
[root@web01 ~]# systemctl start nginx
[root@web01 ~]# ps -ef |grep nginx (过滤进程)
root 8398 1 0 10:51 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 8399 8398 0 10:51 ? 00:00:00 nginx: worker process
root 8425 7482 0 10:51 pts/0 00:00:00 grep --color=auto nginx
检查端口
[root@web01 ~]# ss -lntup |grep nginx
tcp LISTEN 0 128 *:80 *:* users:(("nginx",pid=8399,fd=6),("nginx",pid=8398,fd=6))
启动的方式
systemctl start nginx ===== nginx
systemctl reload nginx ===== nginx -s reload
systemctl stop nginx ===== nginx -s stop
nginx常用命令说明
[root@web01 ~]# nginx -h
-?,-h :this help
-v :show version and exit 显示版本信息
-V :show version and configure options then exit 显示版本信息还有配置信息
-t :test configuration and exit 检测配置文件是否符合语法规范
-T : test configuration, dump it and exit 既测试文件,输出,备份,保存使用
-s signal : send signal to a master process: stop, quit, reopen, reload 控制服务平滑重启 停止
-p prefix : set prefix path (default: /etc/nginx/) 指定程序路径
-c filename : set configuration file (default: /etc/nginx/nginx.conf)
一、查看nginx主次配置文件
nginx服务的配置文件信息
[root@web01 ~]# cd /etc/nginx/
[root@web01 nginx]# ll nginx.conf
-rw-r--r-- 1 root root 643 Dec 4 23:01 nginx.conf 首先加载主配置文件
主配置文件内容详解
nginx.conf文件内容说明:
user nginx; ---指定worker进程所管理用户信息
worker_processes 1; ---修改服务worker进程数量(建议修改数值和CPU核数相等 不能大于CPU核数的2倍)
error_log /var/log/nginx/error.log warn; --- 指定错误日志 warn日志格式/只显示警告信息
日志错误级别:
debug --- 调试级别 会产生的信息比较多
info --- 信息级别 会产生的信息比较多
notice --- 通知级别 会产生的信息比较少
warn --- 警告级别 会产生错误信息 企业配置级别
error --- 错误级别 会影响服务运行 企业配置级别
crit(critical) --- 严重级别 会导致服务无法运行
alert --- 报警级别 会导致服务无法运行
emerg --- 崩溃级别 会导致服务无法运行
pid /var/run/nginx.pid; --- 定义pid文件存放路由
events { ---evens模块(区域)
worker_connections 2048; --- 定义worker进程连接数(建议小于系统打开文件数) #加大文件描述符-调整打开文件数量
echo '* - nofile 65535 ' >>/etc/security/limits.conf
tail -1 /etc/security/limits.conf
}
http { ---http区域
include /etc/nginx/conf.d/*.conf; --- include指令用于加载额外配置信息
include /etc/nginx/mime.types; --- 加载媒体资源类型文件
媒体资源类型文件中有的扩展名文件 可以被浏览器直接解析
媒体资源类型文件中没有的扩展名文件
可以被浏览器直接下载
default_type application/octet-stream; --- 定义了nginx访问日志的格式
nginx的内置变量
log_format main
'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
nginx内置变量 :
'$remote_addr 客户端ip地址
$remote_user 远程用户(空)
[$time_local] 时间
"$request" 请求报文的起始行 $request_uri 只取出uri
'$status 状态码
$body_bytes_sent 身体 字节 发送 服务端发给客户端大小(每个文件的大小)
"$http_referer" 记录着用户从哪里跳转过来的
'"$http_user_agent" 用户浏览器
"$http_x_forwarded_for"'; 负载均衡: web服务器用来记录用户真实ip地址
access_log /var/log/nginx/access.log main; 指定访问日志的位置和使用格式
sendfile on; 开启高效传输模式
keepalive_timeout 65; 超时时间
}
次配置文件的详解
[root@web01 nginx]# ll /etc/nginx/conf.d/
total 4
-rw-r--r-- 1 root root 1093 Dec 4 23:01 default.conf 其次加载默认配置文件
[root@web01 conf.d]# vim default.conf
server { --- 可以定义网站信息(定义虚拟主机信息)www.oldboy.com
listen 80; --- 指定监听的地址信息或者端口信息
server_name localhost; --- 指定网站地址信息
location / {
root /usr/share/nginx/html; ---指定站点目录
index index.html index.htm; --- 指定首页文件
}
error_page 404 500 502 503 504 /50x.html; --- 设置优雅显示错误信息
location = /50x.html { --- 指定优雅显示文件路径信息
root /usr/share/nginx/html; --- 指定默认的站点目录
}
}