---
title: "ubuntu 9.10下从源码安装nginx"
author: "itang"
date: "2010-12-04T19:28:35Z"
tags: []
categories: ["非技术"]
slug: "ubuntu-9-10-nginx"
draft: false
lastmod: "2010-12-04T19:30:49Z"
id: 833441
url: "https://itang.iteye.com/blog/833441"
---

(douban提示有可能有不良广告信息？？？！ ，暂时把最新内容贴到此处)

1 获取源码
    $ wget http://nginx.org/download/nginx-0.9.1.tar.gz
    $ tar zxvf nginx-0.9.1.tar.gz
    $ cd nginx-0.9.1/
    
2 安装依赖的包
    $ sudo apt-get install libssl-dev gcc libpcre3-dev zlib1g-dev libperl-dev

    (提示： 可使用apt-cache search搜索要安装的包，如sudo apt-cache search pcre)
       
3 编译配置：
    使用http://wiki.nginx.org/NginxInstallOptions 中的example3

    $ ./configure \  
    --prefix=/usr \  
    --conf-path=/etc/nginx/nginx.conf \  
    --http-log-path=/var/log/nginx/access_log \  
    --error-log-path=/var/log/nginx/error_log \  
    --pid-path=/var/run/nginx.pid \  
    --http-client-body-temp-path=/var/tmp/nginx/client \  
    --http-proxy-temp-path=/var/tmp/nginx/proxy \  
    --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \  
    --with-md5-asm --with-md5=/usr/include \  
    --with-sha1-asm \  
    --with-sha1=/usr/include \  
    --with-http_realip_module \  
    --with-http_ssl_module \  
    --with-http_perl_module \  
    --with-http_stub_status_module

4 编译安装
    $ make && sudo  make instal
    
    验证安装是否成功
    $ nginx -v
    nginx: nginx version: nginx/0.9.1
    
5 运行前环境准备
    5.1 创建相关目录
    $ sudo mkdir -p /var/tmp/nginx/client
    $ sudo mkdir -p /var/tmp/nginx/fastcgi
    $ sudo mkdir -p /var/tmp/nginx/proxy

    5.2 添加nginx默认组
    $ sudo adduser --system --no-create-home --disabled-login --disabled-password --group nginx

6 运行nginx
    $ sudo nginx
    
    验证nginx运行是否成功
    $ curl -i http://localhost
    HTTP/1.1 200 OK
    Server: nginx/0.9.1
    Date: Fri, 03 Dec 2010 02:34:01 GMT
    Content-Type: text/html
    Content-Length: 151
    Last-Modified: Fri, 03 Dec 2010 02:00:40 GMT
    Connection: keep-alive
    Accept-Ranges: bytes

    <html>
    <head>
    <title>Welcome to nginx!</title>
    </head>
    <body bgcolor="white" text="black">
    <center><h1>Welcome to nginx!</h1></center>
    </body>
    </html>

7 将nginx 设置为系统服务
    $ wget http://nginx-init-ubuntu.googlecode.com/files/nginx-init-ubuntu_v2.0.0-RC2.tar.bz2
    $ tar jxvf nginx-init-ubuntu_v2.0.0-RC2.tar.bz2
    $ gedit nginx
        更新为以下值:
        DAEMON=/usr/sbin/nginx
        NGINX_CONF_FILE="/etc/nginx/nginx.conf"
    $ mv nginx /etc/init.d/
    $ sudo /usr/sbin/update-rc.d -f nginx defaults