赞
踩
系统版本:centos7.9-2009
nginx版本:1.20.2
解压:
tar -zxvf nginx-1.20.2.tar.gz
执行:
./configure
./configure: error: C compiler cc is not found
解决:安装编译器
yum -y install gcc gcc-c++ autoconf automake make
./configure: error: the HTTP rewrite module requires the PCRE library.
解决:
yum -y install pcre-devel
./configure: error: the HTTP gzip module requires the zlib library.
解决:
yum install -y zlib-devel
解决三个问题后配置成功
- make
- make install
- # 找到nginx所在路径
- whereis nginx
- # 进入nginx路径
- cd /usr/local/nginx/sbin
- # 启动nginx
- ./nginx
访问centos7的ip
直接访问访问不到。需要关闭防火墙的80端口
- # 查看防火墙放开的端口
- firewall-cmd --zone=public --list-ports
- # 放开指定端口
- firewall-cmd --zone=public --add-port=80/tcp --permanent
- # 配置立即生效
- firewall-cmd --reload
- # 关闭指定端口
- firewall-cmd --zone=public --remove-port=5672/tcp --permanent
出现如下页面即成功
- # 打开环境变量配置文件
- vim /etc/profile
- # 在末尾加入nginx的位置
- export NGINX_HOME=/usr/local/nginx
- export PATH=$PATH:$NGINX_HOME/sbin
- # 使配置生效
- source /etc/profile
- # 校验配置是否成功,查看nginx版本
- nginx -v
1、进入到cd /lib/systemd/system目录
2、创建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
- ExecStop=/usr/local/nginx/sbin/nginx -s quit
- PrivateTmp=true
-
- [Install]
- WantedBy=multi-user.target
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
保存退出
3、加入开机自启
systemctl enable nginx
4、其他一些服务控制命令
- systemctl start nginx.service 启动nginx服务
- systemctl stop nginx.service 停止服务
- systemctl restart nginx.service 重新启动服务
- systemctl list-units --type=service 查看所有已启动的服务
- systemctl status nginx.service 查看服务当前状态
- systemctl enable nginx.service 设置开机自启动
- systemctl disable nginx.service 停止开机自启动
5、查看加入开机启动的项目
systemctl list-unit-files
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。