nginx的安装与配置,中途遇到问题的解决

我使用的是ubuntu13.04系统,在安装nginx的时候遇到如下几个问题,然后找思路解决的,nginx 的下载与安装

 

wget http://nginx.org/download/nginx-1.0.11.tar.gz
tar zxvf nginx-1.0.11.tar.gz
./configure
make
make install

 

安装的时候出现错误如下:

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

You can either disable the module by using --without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using --with-pcre=<path> option.

 

解决方法,安装pcre包,代码如下:

 

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz
tar zxvf pcre-8.37.tar.gz
./configure
make
make install

 

然后再去安装 nginx,重复第一步,结果如下,说明安装好了:

Configuration summary

  + using system PCRE library

  + OpenSSL library is not used

  + md5: using system crypto library

  + sha1: using system crypto library

  + using system zlib library

 

  nginx path prefix: "/usr/local/nginx"

  nginx binary file: "/usr/local/nginx/sbin/nginx"

  nginx configuration prefix: "/usr/local/nginx/conf"

  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"

  nginx pid file: "/usr/local/nginx/logs/nginx.pid"

  nginx error log file: "/usr/local/nginx/logs/error.log"

  nginx http access log file: "/usr/local/nginx/logs/access.log"

  nginx http client request body temporary files: "client_body_temp"

  nginx http proxy temporary files: "proxy_temp"

  nginx http fastcgi temporary files: "fastcgi_temp"

  nginx http uwsgi temporary files: "uwsgi_temp"

  nginx http scgi temporary files: "scgi_temp"

 

接着启动nginx报错如下:

./nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

通过这个命令查看:ldd $(which /usr/local/nginx/sbin/nginx)

结果如下显示:

linux-vdso.so.1 =>  (0x00007fffa89fe000)

libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fc08b3c3000)

libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007fc08b18a000)

libpcre.so.1 => not found

libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007fc08adae000)

libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fc08ab97000)

libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc08a7cd000)

/lib64/ld-linux-x86-64.so.2 (0x00007fc08b5fa000)

libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fc08a5c9000)

 

 解决方法:添加软链接,          ln -s /usr/local/lib/libpcre.so.1  /lib/x86_64-linux-gnu/libpcre.so.1

 

最后启动nginx,没有报错,启动成功。

 

<think>好的,用户遇到了在编译Nginx时遇到的make错误,需要解决方案。首先,我需要回忆一下常见的Nginx编译错误可能的原因。根据引用[2],用户在安装Nginx时可能需要先安装依赖项,比如gcc、pcre、zlib和openssl。可能用户没有正确安装这些依赖,导致make失败。另外,配置步骤是否正确执行?例如,运行./configure时是否有错误提示,这可能会导致后续的make失败。 其次,用户的环境是否正确配置?比如,是否有足够的权限,或者是否在正确的目录下执行了命令。还有,是否有缺失的库文件或者头文件?例如,如果pcre库没有安装,configure可能会报错,进而导致make失败。 另外,查看具体的错误信息是关键。用户需要提供make时的具体错误输出,才能更准确地诊断问题。例如,如果报错是关于某个未定义的函数,可能是缺少某个开发包。或者,如果提示文件找不到,可能是路径问题。 根据引用[2]中的步骤,用户可能漏掉了某个依赖的安装,或者在配置时没有正确指定路径。比如,如果openssl没有正确安装,可能需要使用--with-openssl=<path>选项来指定位置。 还需要考虑系统版本和Nginx版本的兼容性问题。用户使用的是Nginx 1.18.0,是否当前的CentOS 7系统兼容?是否存在已知的问题? 此外,权限问题也可能导致编译失败,例如用户是否有权限在目标目录进行写入操作。建议用户检查目录权限,或者尝试以sudo权限运行命令。 最后,建议用户运行make clean后重新执行configure和make,确保没有残留的中间文件干扰编译过程。如果问题依旧,查看config.log文件中的详细错误信息,帮助定位问题根源。</think>### Nginx make 报错解决方案 在编译Nginx时遇到`make`错误,通常依赖缺失、配置参数错误或环境变量问题相关。以下是分步解决方案: --- #### **1. 确认基础依赖安装** Nginx编译依赖以下组件,需通过yum安装: ```bash yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel ``` - **gcc**: 编译C/C++代码的核心工具 - **pcre**: 支持正则表达式解析 - **zlib**: 提供GZIP压缩功能 - **openssl**: 支持HTTPS协议[^2] 若安装后仍报错,检查是否遗漏开发包(如`openssl-devel`而非仅`openssl`)。 --- #### **2. 检查配置步骤** 在解压后的Nginx目录中,需先执行配置脚本: ```bash ./configure ``` - **常见错误**:若报错`... not found`,可能是依赖库路径未识别。需通过参数指定路径,例如: ```bash ./configure --with-pcre=/usr/local/pcre --with-zlib=/usr/local/zlib ``` - **关键操作**:执行后检查输出末尾是否提示`configuration is complete`,否则需根据日志调整参数[^2]。 --- #### **3. 排查具体报错信息** 根据`make`阶段的错误类型针对性解决: - **示例1:`undefined reference to 'xxxx'`** 通常为库文件链接失败,需确认依赖库安装完整,或通过`LDFLAGS`指定库路径: ```bash export LDFLAGS="-L/usr/local/openssl/lib" ./configure ``` - **示例2:`fatal error: xxx.h: No such file or directory`** 头文件缺失,需安装对应开发包(如`openssl-devel`),或通过`CFLAGS`指定头文件路径: ```bash export CFLAGS="-I/usr/local/openssl/include" ./configure ``` --- #### **4. 清理并重新编译** 若配置或编译中途失败,需清理残留文件: ```bash make clean ./configure make make install ``` --- #### **5. 验证系统资源** - **磁盘空间**:`df -h`检查编译目录是否空间不足。 - **权限问题**:若安装到`/usr/local/nginx`,需确保当前用户有写入权限,或使用`sudo`。 --- #### **6. 特殊案例:缺失`nginx.pid`文件** 若编译成功但运行时报错`nginx.pid缺失`,需手动生成: ```bash nginx -c /usr/local/nginx/conf/nginx.conf nginx -s reload ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值