一. 安装环境
操作系统:Centos 7. 最小化安装
服务器地址:***
二.安装过程:
1. 安装wget
yum install wget -y
2. 下载Nginx
wget http://nginx.org/download/nginx-1.25.1.tar.gz
官网下载 Nginx: http://nginx.org/en/download.html
3. 解压安装包, 并安装https, zlib
tar -xf nginx-1.25.1.tar.gz
# 安装https
yum -y install openssl openssl-devel
# 安装一个压缩和解压缩的环境。
yum -y install zlib zlib-devel
4. 编译安装Nginx
1)进入解压目录
cd nginx-1.25.1
yum install gcc automake autoconf libtool make -y
2)安装到指定目录并配置安装ssl证书,添加两个模块(推荐:需提前建好目录)
# prefix参数是指定固定目录
./configure --prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_module
3)编译并安装(如没有权限,可使用sudo以root用户权限安装)
# 执行make命令
make distclean&make
# 执行make install命令
make install
4)安装后的目录
[root@rpp-vm00 nginx-1.25.1]# whereis nginx
nginx: /usr/local/nginx
[root@rpp-vm00 nginx-1.25.1]# cd /usr/local/nginx/
[root@rpp-vm00 nginx]# ll
总用量 0
drwxr-xr-x 2 root root 333 6月 27 09:53 conf
drwxr-xr-x 2 root root 40 6月 27 09:53 html
drwxr-xr-x 2 root root 6 6月 27 09:53 logs
drwxr-xr-x 2 root root 19 6月 27 09:53 sbin
三. 原始命令启动Nginx
[root@rpp-vm00 nginx]# cd /usr/local/nginx/sbin/
[root@rpp-vm00 sbin]# ll
总用量 5940
-rwxr-xr-x 1 root root 6079336 6月 27 09:53 nginx
# 不报错就是启动成功
[root@rpp-vm00 sbin]# ./nginx
[root@rpp-vm00 sbin]#
[root@rpp-vm00 sbin]# ps -ef | grep nginx
root 3960 1 0 09:57 ? 00:00:00 nginx: master process ./nginx
nobody 3961 3960 0 09:57 ? 00:00:00 nginx: worker process
root 3963 1155 0 09:57 pts/0 00:00:00 grep --color=auto nginx
四. 配置path路径
# vi /etc/profile
PATH=$PATH:/usr/local/nginx/sbin
# source /etc/profile
五. systemctl配置
1. nginx.service 文件创建
vim /etc/systemd/system/nginx.service
2. 写入脚本
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
3. 重新加载配置
systemctl daemon-reload
# 启动命令
systemctl enable nginx
systemctl start nginx
systemctl status nginx
systemctl stop nginx
systemctl restart nginx