主页 > 知识库 > 服务器 > Linux/BSD >

Ubuntu编译Nginx

来源:feiyan 作者:feiyan 发表于:2012-11-15 15:27  点击:
之前在一台VPS编译了 Nginx 环境,1G内存, Ubuntu 12.04 Server版64位。 首先安装基础编译环境: ##g++在 CentOS 服务器叫做gcc-c++sudo apt-get install gcc g++ automake make Wget最新版的Nginx源码,切换到文件夹开始编译,在不添加编译参数的情况下会

之前在一台VPS编译了Nginx环境,1G内存,Ubuntu 12.04 Server版64位。

首先安装基础编译环境:

##g++在CentOS服务器叫做gcc-c++
sudo apt-get install gcc g++ automake make

Wget最新版的Nginx源码,切换到文件夹开始编译,在不添加编译参数的情况下会以此出现下属三个错误:

错误一: 缺少 pcre library
./configure: error: the HTTP rewrite module requires the PCRElibrary.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=option.

错误二: 缺少 openssl 库
./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.

错误三: 缺少 zlib 库
./configure: error: the HTTP gzip module requires the zlib library. You can either disable the module by using --without-http_gzip_module option, or install the zlib library into the  system, or build the zlib library statically from the source with nginx by using --with-zlib= option.

则按照错误依次编译三个缺少的库,其他报错类推:

sudo apt-get install libpcre3-dev libssl-dev openssl

安装 chkconfig :

sudo apt-get install chkconfig ##自启动

最后编译Nginx即可:

## 均采用默认配置,也可以按启用添加自己的扩展
sudo ./configure –prefix=/usr/local/nginx
sudo make && make install
   
## 显示下列则编译成功
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(可选):

##建立软链接
sudo ln -s /usr/local/nginx/sbin/nginx /etc/init.d/
##启动nginx
/etc/init.d/nginx

Job Done!

    有帮助
    (0)
    0%
    没帮助
    (0)
    0%