1、服务器,不用说
2、连接控制,XShell或SecureCRT
二、方案一yum install nginx
三、重点:方案二
1、安装依赖
yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
2、创建临时目录
cd /opt
mkdir nginx
cd nginx
3、下载安装包并解压
wget -c https://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz
4、进入解压目录
cd nginx-1.18.0
5、配置
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_sub_module --with-http_gzip_static_module --with-pcre --with-stream
6、编译安装
make && make install
7、此时已完成安装,安装目录
/usr/local/nginx
8、systemctl管理
1)进入系统目录
cd /usr/lib/systemd/system/
2)创建服务文件
touch nginx.service
3)编辑nginx.service,复制内容
vim nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
4)重新加载服务配置
systemctl daemon-reload
5)启动
systemctl start nginx
## 启动可能失败,因为端口可能冲突
6)修改端口
cd /usr/local/nginx/conf/
vim nginx.conf
listen 80 -> listen 8081
或者其他端口
7)重试启动
systemctl start nginx
8)完成
若还启动失败,请自行通过错误提示排查问题
9)备份命令
## 停止ng服务
systemctl stop nginx
## 查看启动状态
systemctl status nginx