软件环境:CentOS7.6+Nginx1.16.0+mysql8.0.17+php7.2.21
服务器: IBM x3850 X5
1.查看系统版本/安装常用软件(系统最小化安装)
[root@XiaoFeng ~]# cat /etc/centos-release CentOS Linux release 7.6.1810 (Core) [root@XiaoFeng ~]#yum install -y wget vim net-tools
2.下载安装包
[root@XiaoFeng sjd]# wget http://nginx.org/download/nginx-1.16.0.tar.gz
3.安装依赖包
[root@XiaoFeng sjd]# yum install -y gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel [root@XiaoFeng sjd]# tar -zxvf nginx-1.16.0.tar.gz [root@XiaoFeng sjd]# cd nginx-1.16.0 [root@XiaoFeng nginx-1.16.0]# useradd -s /sbin/nologin nginx #创建Nginx运行用户和组
4.编译配置
[root@XiaoFeng nginx-1.16.0]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx/ --with./configure --user=nginx --group=nginx --prefix=/usr/local/nginx/ --with-http_v2_module --with-http_ssl_module --with-http_sub_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-http_realip_module [root@XiaoFeng nginx-1.16.0]# make && make install [root@XiaoFeng nginx-1.16.0]# cd /usr/local/nginx/sbin [root@XiaoFeng sbin]# ./nginx //启动Nginx [root@XiaoFeng sbin]# ./nginx -t //验证配置文件是正确 [root@XiaoFeng sbin]# ./nginx -s reload //重启Nginx [root@XiaoFeng sbin]# ./nginx -s stop //停止Nginx [root@XiaoFeng sbin]# ./nginx -v //查看是否安装成功 nginx version: nginx/1.16.0 [root@XiaoFeng sbin]# netstat -ntlp | grep nginx //查看是否启动 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 20949/nginx: master
5.配置Nginx命令和服务并开机启动
[root@XiaoFeng sbin]# vim /usr/lib/systemd/system/nginx.service
#输入下面内容,并保存
[Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ 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=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
#添加执行权限
[root@XiaoFeng sbin]# chmod +x /usr/lib/systemd/system/nginx.service
#启动服务
[root@XiaoFeng sbin]# systemctl start nginx.service //启动 [root@XiaoFeng sbin]# systemctl stop nginx.service //停止 [root@XiaoFeng sbin]# systemctl reload nginx.service //修改配置后重新加载生效 [root@XiaoFeng sbin]# systemctl restart nginx.service //重启 [root@XiaoFeng sbin]# systemctl status nginx //查看服务是否启动
#添加开机启动
[root@XiaoFeng sbin]# systemctl enable nginx.service Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
6.防火墙默认开启,加入放行端口80
[root@XiaoFeng sbin]# firewall-cmd --zone=public --add-port=80/tcp --permanent success [root@XiaoFeng sbin]# firewall-cmd --reload success
配图
本文为 小风原创文章,转载无需和我联系,但请注明来自 小风博客www.hotxf.com