Nginx 源码安装步骤
Nginx 下载源码包地址:http://nginx.org/en/download.html
tar -zxvf nginx-1.22.0.tar.gz ##解压 Nginx 源码包
cd nginx-1.22.0 ##切换对应 Nginx 目录下
./configure ##加载命令
make ##编译命令
make install ##安装命令
vim /etc/profile ##配置 Nginx 环境变量
注:以下两行为 Nginx 环境变量请添加至文件结尾并保存
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
source /etc/profile ##刷新环境变量配置文件使其生效
vim /lib/systemd/system/nginx.service ##在/lib/systemd/system 目录下创建 nginx.service 文件
注:以下为配置文件 nginx.service 的内容:
[Unit]
Description=nginx service
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
注:nginx 启动程序路径请根据自身实际情况进行调整
systemctl start nginx ##启动 Nginx
systemctl enable nginx ##如业务需要请将 Nginx 设置为开机启动
以下为 Nginx 管理命令:
systemctl start nginx ##启动服务
systemctl stop nginx ##停止服务
systemctl restart nginx ##重新启动服务
systemctl list-units --type=service ##查看所有已启动的服务
systemctl status nginx ##查看服务当前状态
systemctl enable nginx ##设置开机自启动
systemctl disable nginx ##停止开机自启动
注:如果最后 Nginx 默认页面无法访问请关闭防火墙
systemctl stop firewalld ##关闭防火墙命令
评论0