确认系统版本
cat /etc/redhat-release
确认网络
ping www.baidu.com
确认yum可用
yum list
确认防火墙
查看防火墙状态
firewall-cmd --state
关闭防火墙
systemctl stop firewalld.service
永久关闭防火墙
systemctl disable firewalld.service
确认SELinux,并关闭
vim /etc/selinux/config
设置disabled
安装依赖库和运行环境
yum -y install gcc make automake pcre-devel zlib zlib-devel openssl openssl-devel
下载安装Nginx
http://nginx.org/
开发版、稳定版、历史版
使用1.20.2
wget http://nginx.org/download/nginx-1.20.2.tar.gz
下载完成
解压压缩包
tar -zxvf nginx-1.20.2.tar.gz
解压到了当前文件夹。。。位置错了。。。删除先
rm -rf nginx-1.20.2
解压到 /usr/local/(服务的安装地)
tar -zxvf nginx-1.20.2.tar.gz -C /usr/local/
Nginx源码编译
查看目录结构
生成编译文件makefile
使用./configure --help
来查看configure命令的参数
创建目录
mkdir -p /var/temp/nginx/client
使用 configure 命令可以生成makefile文件
./configure --prefix=/usr/local/nginx --pid-path=/usr/local/nginx/logs/nginx.pid --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log --with-http_ssl_module --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi
查看当前目录的Makefile文件
编译
make
安装
make install
查看目录
到这里nginx的服务安装完成。。。
展示nginx的目录结构
yum install tree -y
tree /usr/local/nginx
查看nginx进程
ps aux|grep nginx
docker安装Nginx
不同于上面的编译源码安装。。。
查看本机docker版本
docker -v
如果没有安装docker就先安装
yum install -y docker
查看镜像
docker images
没有nginx
docker pull nginx
成功下载了nginx镜像
启动容器
docker run --rm --name nginx-test -p 8080:80 -d nginx
查看运行中的容器
docker ps
在进行docker数据卷挂载
1 先创建本地目录,存放nginx相关文件信息
mkdir -p /opt/nginx/html /opt/nginx/conf
2 拷贝容器内 Nginx 默认配置文件到本地当前目录下的 conf 目录,
容器ID可以查看 docker ps 命令输入中的第一列
本地目录如下:
容器内目录如下:
进行拷贝(吧容器中的配置文件nginx.conf拷贝出来到本地)
docker cp 784ef10392f5:/etc/nginx/nginx.conf /opt/nginx/conf
3 停止容器
4 部署
docker run --rm -d -p 8081:80 --name ngintest-web -v /opt/nginx/html:/usr/share/nginx/html -v /opt/nginx/conf/nginx.conf:/etc/nginx/nginx.conf nginx
这样,我们就成功创建了一个新的容器。。。。。
现在,操作当前本地的下面俩个文件夹,就可以操作docker里面的nginx了
启动nginx服务
(这里使用的是源码安装的nginx进行服务启动的操作)
sbin是命令目录,我们进去
./nginx
查看是否运行
ps -ef|grep nginx
访问
默认80端口
http://192.168.66.100/
核心配置文件:nginx.conf
帮助手册
./nginx -h
服务停止和重启
详细介绍见文档。。。。。
Nginx就是玩配置文件nginx.conf