Nginx 安装
下载 nginx
下载地址:http://nginx.org/en/download.html
将下载好的压缩包拷贝到根目录下
通过xshell如果出现 bash: rz: 未找到命令 ,需要先运行下面的命令
yum -y install lrzsz
安装
- 解压到当前目录
tar -zxvf nginx-1.22.1.tar.gz
-
安装依赖
yum install -y gcc yum install -y pcre pcre-devel yum install -y zlib zlib-devel
-
编译安装
cd /root/nginx-1.22.1 ./configure --prefix=/usr/local/nginx make make install
启动
进入安装好的目录 /usr/local/nginx/sbin
./nginx 启动
./nginx -s stop 快速停止
./nginx -s quit 优雅关闭,在退出前完成已经接受的连接请求
./nginx -s reload 重新加载配置
防火墙设置
关闭防火墙
systemctl stop firewalld
禁止开机启动
systemctl disable firewalld
重启防火墙
systemctl start firewalld
放行端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
安装完成服务
创建服务脚本
vi /usr/lib/systemd/system/nginx.service
文件内容
[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
重新加载系统服务
systemctl daemon-reload
启动
systemctl start nginx
开机启动
systemctl enable nginx
访问:通过CentOS的IP地址即可访问