Centos下編譯安裝nginx

申明

當前文章使用的 Nginx 版本: 1.4.4 stable 下載

.bz2 解壓命令 $ tar jxf file-namephp

.gz 解壓命令 $ tar zxf file-namehtml

推薦事先安裝的一些依賴

$ yum install -y gcc gcc-c++ make cmake autoconf libtool \
libtool-ltdl-devel pcre pcre-devel gd-devel freetype-devel \
libxml2-devel libjpeg-devel libpng-devel openssl-devel \
curl-devel patch libmcrypt-devel libmhash-devel ncurses-devel \
sudo bzip2 bzip2-devel bison perl-devel perl-ExtUtils-Embed \
libcurl-devel libjpeg-devel libpng-devel freetype-devel \
t1lib-devel libicu-devel mhash libmcrypt libmcrypt libiconv \
libxslt-devel openldap-devel

 
添加用戶組nginx

$ groupadd nginx
$ useradd -g nginx -s /sbin/nologin nginx

新建日誌目錄c++

$ mkdir -p /var/nginx/log

編譯安裝Nginxvim

編譯參數app

$ ./configure \
--user=nginx \
--group=nginx \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/usr/local/etc/nginx/nginx.conf \
--error-log-path=/var/nginx/log/nginx/error.log \
--http-log-path=/var/nginx/log/nginx/access.log \
--pid-path=/var/nginx/log/run/nginx.pid \
--lock-path=/var/nginx/log/lock/subsys/nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_perl_module \
--with-mail \
--with-mail_ssl_module > out

安裝curl

$ make
$ make install

注意事項ui

1.若是碰到url

./configure: error: the HTTP rewrite module requires the PCRE library.,請安裝pcre-devel:

$ yum -y install pcre-devel

2.若是使用—with-http_sub_module參數編譯出錯的話,加參數—with-openssl=/download/openssl-1.0.1c, 這裏指定的openssl目錄是源碼包解壓出來的目錄而不是openssl的安裝目錄。日誌

配置文件

新建虛擬主機配置文件

$ vim /usr/local/etc/nginx/vhost.conf

加入

server {
    listen 80;
    server_name foo.com;

    root /www/foo;
    index index.html index.htm index.php;

    location / {
        try_files $uri $uri/ /index.php;
    }

    location ~ \.php$ {
        try_files $uri = 404;

        include fastcgi.conf;
        fastcgi_pass 127.0.0.1:9000;
    }
}

在ningx.conf裏引入虛擬主機配置文件

$ vim /usr/local/etc/nginx/nginx.conf

修改以下

http {
    include       mime.types;
    include       vhosts.conf;   // 引入虛擬主機配置文件
    default_type  application/octet-stream;

Nginx命令

啓動

$ nginx

平滑重啓

$ nginx -s reload

中止

$ nginx -s stop
相關文章
相關標籤/搜索