第一个里程碑:
更新yum源--nginx官方yum仓库下载
官方参考:http://nginx.org/en/linux_packages.html#RHEL-CentOS
第二个里程碑:
配置nginx官方yum源
[root@web01 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
第三个历程:清除yum缓存信息
yum clean all
第四个里程碑:
安装nginx服务
[root@web01 ~]# yum install -y nginx
第五个里程碑:
启动并加入开机自启动
[root@web01 /etc/nginx]# systemctl start nginx 启动nginx
[root@web01 /etc/nginx]# systemctl enable nginx 开机自启nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@web01 /etc/nginx]# systemctl status nginx 查看nginx状态
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2019-06-25 22:10:17 CST; 6min ago
Docs: http://nginx.org/en/docs/
Process: 10364 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Main PID: 10365 (nginx)
CGroup: /system.slice/nginx.service
├─10365 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
└─10366 nginx: worker process
nginx配置文件
[root@web01 /etc/nginx]# cat nginx.conf 《===nginx主配置文件
user nginx; 《===nginx进程所使用的管理用户
worker_processes 1; 《===运行的work进程数量(建议与CPU数量一致)
error_log /var/log/nginx/error.log warn; 《===错误日志存放路径
pid /var/run/nginx.pid; 《===服务运行后产生的pid进程号
events {
worker_connections 1024; 《===每个worker进程支持的最大连接数
}
http {
include /etc/nginx/mime.types; --- 加载指定其它配置文件(媒体资源类型文件)
default_type application/octet-stream; --- 默认识别媒体类型
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 /var/log/nginx/access.log main; 《===该网站的访问日志
sendfile on; --- 和nginx优化有关
#tcp_nopush on; --- 和nginx优化有关
keepalive_timeout 65; --- 连接超时时间 默认单位秒
#gzip on; --- 和nginx优化有关
include /etc/nginx/conf.d/*.conf; #--- 加载conf.d下面的所有.conf扩展配置文件
}
nginx网站配置文件
[root@web01 /etc/nginx/conf.d]# cat default.conf
server {
listen 80; ---指定服务监听信息 默认监听端口信息
server_name localhost; ---指定网站域名信息
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / { ---匹配不同uri,进行不同的配置
root /usr/share/nginx/html; ---指定站点目录路径
index index.html index.htm; ---指定首页文件信息
}
error_page 404 /404.html; ---优雅的显示错误信息
location = /oldboy.jpg { --- 匹配指定50x.html的uri
root /html; --- 指定站点目录
}
}
疑问解答:
01. nginx程序worker进程是什么?
master process:控制服务可以正常运行 老板
worker process:处理用户访问请求 员工
02. nginx配置文件结构:
1)核心配置部分 main 区域
2)事件配置部分 event 区域
3)网站配置部分 http 区域 指定网站功能参数
4)主机配置区域 server 区域 指定每个网站信息(域名 站点目录 首页文件)
5)location配置区域 指定网站特殊功能
运维网站代码上线流程:
第一个历程:编写修改配置文件
vim /etc/nginx/conf.d/www.conf
server {
listen 80;
server_name www.oldboy.com;
location / {
root /html/www;
index index.html index.htm;
}
systemctl restart nginx
第二个历程:根据配置文件调整系统环境
mkdir /html/www
第三个历程:将开发人员写的代码上传到站点目录 开发人员-- gitlab(版本控制服务)-- 运维人员
将代码包放入站点目录---解压
代码更新,要进行备份(回退还原)
[root@web01 /html/www]# ll
total 156
-rw-r--r-- 1 root root 159425 Jun 26 20:35 3Dmofang.zip
[root@web01 /html/www]# unzip 3Dmofang.zip
[root@web01 /html/www]# ll
total 156
-rw-r--r-- 1 root root 159425 Jun 26 20:35 3Dmofang.zip
drwxr-xr-x 4 root root 45 Apr 1 17:18 HTML5 3D魔方小游戏
[root@web01 /html/www]# mv HTML5\ 3D魔方小游戏/ .
mv: ‘HTML5 3D魔方小游戏/’ and ‘./HTML5 3D魔方小游戏’ are the same file
[root@web01 /html/www]# mv HTML5\ 3D魔方小游戏/* .
[root@web01 /html/www]# ll
total 160
-rw-r--r-- 1 root root 159425 Jun 26 20:35 3Dmofang.zip
drwxr-xr-x 2 root root 23 Mar 20 10:29 css
drwxr-xr-x 2 root root 6 Jun 27 02:23 HTML5 3D魔方小游戏
-rw-r--r-- 1 root root 2444 Apr 1 17:22 index.html
drwxr-xr-x 2 root root 42 Mar 20 10:29 js
第四个历程:确认域名解析
aliyun进行域名配置
第五个历程:修改调整数据库
SQL语句
第六个历程:访问网站进行测试