卡卷网
当前位置:卡卷网 / 每日看点 / 正文

Nginx 安装及配置详解有哪些内容?

作者:卡卷网发布时间:2025-04-28 23:29浏览数量:12次评论数量:0次

1. 源码编译安装nginx步骤(自定义配置)

1.1 安装编译依赖

sudo yum install -y gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

Nginx 安装及配置详解有哪些内容?  第1张

1.2 下载并解压源码

注:安装包也可到nginx官网下载页面下载nginx: download。

wget http://nginx.org/download/nginx-1.26.3.tar.gz tar -zxvf nginx-1.24.0.tar.gz -C /usr/local/nginx cd /usr/local/nginx/nginx-1.26.3

Nginx 安装及配置详解有哪些内容?  第2张

1.3 配置编译选项

./conp --prefix=/usr/local/nginx --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-pcre

1.4 编译并安装

make && sudo make install

Nginx 安装及配置详解有哪些内容?  第3张

2. 设置开机自启动

2.1 创建 Systemd 服务文件

/usr/lib/systemd/system/nginx.service 写入以下内容。

注:PIDFile、ExecStart、ExecReload、ExecStop要根据自己安装nginx的编译选项进行配置,WantedBy选项注意拼写和空格。

vim /usr/lib/systemd/system/nginx.service [Unit] Description=Nginx Web Server After=network.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid 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

2.2 重载配置并启动

sudo systemctl daemon-reload sudo systemctl start nginx sudo systemctl stop nginx sudo systemctl restart nginx sudo systemctl enable nginx # 设置开机自启动 sudo systemctl is-enabled nginx #enabled

2.3 验证

验证前需要放开nginx的默认端口号。

firewall-cmd --add-port=80/tcp permanent firewall-cmd --reload firewall-cmd --zone=public --list-ports #出现80/tcp

Nginx 安装及配置详解有哪些内容?  第4张

在浏览器中输入: IP地址:80,出现Welcome to nginx即为成功。

Nginx 安装及配置详解有哪些内容?  第5张

END

免责声明:本文由卡卷网编辑并发布,但不代表本站的观点和立场,只提供分享给大家。

卡卷网

卡卷网 主页 联系他吧

请记住:卡卷网 Www.Kajuan.Net

欢迎 发表评论:

请填写验证码