Linux Nginx 安装配置说明


Nginx 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过两年半了。 Igor 将源代码以类 BSD 许可证的形式发布

1、为了确保能在 Nginx 中使用正则表达式进行更灵活的配置,安装之前需要确定系统是否安装有 PCRE(Perl Compatible Regular Expressions)包。您可以到ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/下载最新的 PCRE 源码包,使用下面命令下载编译和安装 PCRE 包

软件我都下载到 /software/nginx

Nginx的安装需要依赖于gcc、openssl-devel、pcre-devel、zlib-devel

1、先安装 openssl

yum install openssl

 2、 下载 pcre 软件 Rewrite 配置的使用

cd /software/nginx

http://jaist.dl.sourceforge.net/project/pcre/pcre/8.32/pcre-8.32.zip

unzip pcre-8.32.zip
 cd pcre-8.32

./configure

make

make install

3、安装 zlib

cd /software/nginx

wget http://zlib.net/zlib-1.2.7.tar.gz
 tar -zxvf zlib-1.2.7.tar.gz
 cd zlib-1.2.7
 ./configure
 make
 make install

4、下载 Nginx 软件

http://nginx.org

配置和安装

./configure –prefix=/usr/local/nginx –with-pcre=/software/nginx/pcre-8.32 –with-http_ssl_module –with-http_stub_status_module –with-http_sub_module

make

make install

注: –with-pcre=/software/nginx/pcre-8.32 指的是pcre-8.32 的源码路径

 
在 nginx.conf 的 server 中添加 :
rewrite_log on;
 error_log logs/rewrite.error.log notice; #可以查看rewrite是否正确

5、启动 Nginx

/usr/local/nginx/sbin/nginx -t    #测试配置文件是否正确

出现如下则正确:

/usr/local/nginx/sbin/nginx  #启动Nginx

如出现以下错误:

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

解决办法如下:

在RedHat 64位机器上, nginx可能读取的pcre文件为/lib64/libpcre.so.1文件.

ln -s /lib64/libpcre.so.0.0.1 /lib64/libpcre.so.1

ln -s /lib/libpcre.so.0.0.1 /lib/libpcre.so.1

更多Nginx相关教程见以下内容

CentOS 6.2实战部署Nginx+MySQL+PHP

使用Nginx搭建WEB服务器

搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程

CentOS 6.3下Nginx性能调优

CentOS 6.3下配置Nginx加载ngx_pagespeed模块

CentOS 6.4安装配置Nginx+Pcre+php-fpm

Nginx安装配置使用详细笔记

Nginx日志过滤 使用ngx_log_if不记录特定日志

Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里

本文永久更新链接地址

相关内容