为了确保能在 Nginx 中使用正则表达式进行更灵活的配置,安装之前需要确定系统是否安装有 PCRE(Perl Compatible Regular Expressions)包。您可以到 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 下载最新的 PCRE 源码包,使用下面命令下载编译和安装 PCRE 包:
# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.01.tar.gz
# tar zxvf pcre-8.01.tar.gz
# cd pcre-8.01
# ./configure
# make
# sudo make install
下面开始nginx的安装:
# tar zxvf nginx-0.8.48.tar.gz
# cd nginx-0.8.48
# ./configure
# make
# sudo make install
如果你在make 的时候出现 make: *** 没有规则可以创建“default”需要的目标“build”。 停止。那么说明你跟我犯了同一个错误,你一定没有注意configure时的错误提示:
./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= options.
看清楚否?没有opensll library!怎么办?装呗!
# sudo apt-get install openssl
# sudo apt-get install libssl-dev
安装成功后 /usr/local/nginx 目录下有四个子目录分别是:conf、html、logs、sbin 。其中 Nginx 的配置文件存放于 conf/nginx.conf,Nginx 只有一个程序文件位于 sbin 目录下的 nginx 文件。确保系统的 80 端口没被其他程序占用,运行 sbin/nginx 命令来启动 Nginx,打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。 启动nginx时,提示:error while loading shared libraries: libpcre.so.0: error while loading shared libraries: libpcre.so.0: cannot open shared object file: No such file or directory # sudo ln -s /usr/local/lib/libpcre.so.0 /usr/lib/libpcre.so.0