目录:
1.安装nginx
2.nginx做反向代理
3.nginx负载均衡
4.nginx动静分离
5.配置文件nginx.conf
一、安装
yum安装
# 版本:nginx-1.16.1.tar.gz
# EPEL 仓库中有 Nginx 的安装包。
yum install epel-release
# 安装 Nginx
yum install nginx
# 设置 Nginx 开机启动
systemctl enable nginx
# 启动 Nginx
systemctl start nginx
# 检查 Nginx 的运行状态
systemctl status nginx
# 如果你的服务器开启了防火墙,则需要同时打开 80(HTTP)和 443(HTTPS)端口
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
# 本地验证,如果有输出的html证明安装成功
curl 127.0.0.1
# 查看nginx进程
ps -ef | grep nginx
编译安装
# 下载nginx
wget http://nginx.org/download/nginx-1.12.2.tar.gz
# Gcc(用于编译c、c++代码):
yum install gcc c++
# Pcre(用c语言编写的正则表达式函数库)):
yum install -y pcre pcre-devel
# Zlib(用于数据压缩的函式库):
yum install -y zlib zlib-devel
# OpenSSL(安全套接字层密码库):
yum install -y openssl openssl-devel
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
# 编译Nginx
tar -zxvf nginx-1.12.2tar.gz
cd nginx-1.12.2
./configure
make
make install
# 在CentOS7下将nginx添加到systemctl(创建并配置nginx.service文件)
# 创建配置文件
vim /usr/lib/systemd/system/nginx.service
#配置文件内容
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
# 重新加载 systemd
systemctl daemon-reload
二、通过 systemctl 管理 Nginx
# 启动 Nginx
systemctl start nginx
# 停止 Nginx
systemctl stop nginx
# 重启 Nginx
systemctl restart nginx
# 重新加载 Nginx
systemctl reload nginx
# 设置开机启动 Nginx
systemctl enable nginx
# 关闭开机启动 Nginx
systemctl disable nginx
三、yum安装的配置文件
# 启动脚本路径
/usr/sbin/nginx
# 主配置文件路径
/etc/nginx/nginx.conf
# 服务配置文件路径。如:/etc/nginx/conf.d/dongxibao.top.80.conf
/etc/nginx/conf.d
# Nginx 日志文件(access.log 和 error.log )路径
/var/log/nginx/
四、yum安装的卸载nginx
# 停止nginx服务
nginx -s stop
# 删除匹配
yum remove nginx
# 删除文件
rm -rf /usr/sbin/nginx
rm -rf /etc/nginx
rm -rf /etc/init.d/nginx
rm -rf /usr/local/sbin/nginx