Centos下编译安装nginx - Mkk侯
申明
当前文章使用的 Nginx 版本: 1.4.4 stable 下载
.bz2 解压命令 $ tar jxf file-name
.gz 解压命令 $ tar zxf file-name
推荐事先安装的一些依赖
$ 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
添加用户组
$ groupadd nginx$ useradd -g nginx -s /sbin/nologin nginx
新建日志目录
$ mkdir -p /var/nginx/log
编译安装Nginx
编译参数
$ ./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
安装
$ make$ make install
注意事项
1.如果碰到
./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