源码安装Nginx

安装Nginx时报错

./configure: error: the HTTP rewrite module requires the PCRE library.

安装pcre-devel解决问题
yum -y install pcre-devel


错误提示:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library.   You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.

解决办法:

yum -y install openssl openssl-devel


总结:

yum -y install pcre-devel openssl openssl-devel

./configure --prefix=/usr/local/nginx

make

make install

一切搞定

nginx源码安装的详细步骤如下: 1. **准备工作**:关闭防火墙,检查防火墙状态。 2. **下载并解压源代码包**: - 创建存放源码的目录并进入:`mkdir /usr/local/src/nginx_source; cd /usr/local/src/nginx_source/`。 - 下载最新版本的nginx源代码包,如:`wget https://nginx.org/download/nginx-1.24.0.tar.gz`。 - 解压源代码包:`tar xzf nginx-1.24.0.tar.gz`,并进入解压后的目录:`cd nginx-1.24.0/` [^3]。 3. **安装依赖环境**:安装Nginx的依赖包。 4. **编译安装nginx**: - 执行configure脚本生成编译配置文件Makefile,示例配置如下: ```bash ./configure --prefix=/usr/local/nginx \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_v2_module \ --with-http_realip_module \ --with-http_gzip_static_module \ --with-http_stub_status_module \ --with-pcre \ --with-stream \ --with-stream_ssl_module ``` - 执行`make`命令编译源代码。 - 执行`make install`安装软件 [^3]。 5. **创建管理用户**: - 创建一个名为nginx的组账户:`groupadd -r nginx`。 - 创建一个属于该组的同名用户,不允许该用户登录和创建主目录:`useradd -s /sbin/nologin -g nginx -r nginx` [^1]。 6. **通过软链接优化(可选)**:可根据实际情况进行软链接的创建。 7. **检查、启用、添加系统管理**: - 检查安装nginx之后是否拥有nginx这个用户:`id nginx`。 8. **添加nginx系统服务**: - 停掉nginx。 - 创建`nginx.service`文件,添加以下内容: ```ini [Unit] Description=The nginx HTTP and reverse proxy server After=network.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target ``` [^5] 9. **启动服务测试**:启动nginx服务并进行测试。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值