1、下载nginx
wget http://nginx.org/download/nginx-1.6.0.tar.gz
2、解压
tar zxvf nginx-1.6.0.tar.gz
进入nginx目录,cd nginx-1.6.0
3、配置
./configure
配置过程中可能会报如下错误:
checking for PCRE library not found
checking for PCRE library in /usr/local/ not found checking for PCRE library in /usr/include/pcre/ not found checking for PCRE library in /usr/pkg/ not found checking for PCRE library in /opt/local/ not found
./configure: error: the HTTP rewrite module requires the PCRE library. 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=<path> option.
解决办法,下载pcre库,并编译和安装:
PCRE库是实现Perl正则表达式的基础。如果系统中缺少此库需要编译安装。可以从著名的开源软件网站sourceforge上下载:
http://sourceforge.net/projects/pcre/files/pcre/。
仍然是下载后解压、配置、编译和安装:
[***]tar -zxvf pcre-8.35.tar.gz
[***]cd pcre-8.35
[***]./configure
[***]make
[***]make install
4、编译与安装nginx
make
make install
5、启动nginx
/usr/local/nginx/sbin/nginx
注:在64位系统上启动时有可能报如下错误:
Nginx: error while loading shared libraries: libpcre.so.1
解决办法如下:
ln -s /usr/local/lib/libpcre.so.1 /lib64/libpcre.so.1
再将启动即可。
6、查看是否启动成功
[root@localhost ~]# ps -aef | grep nginx
root 28295 1 0 22:52 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 28296 28295 0 22:52 ? 00:00:00 nginx: worker process
root 28615 28587 0 23:09 pts/0 00:00:00 grep nginx
[root@localhost ~]#
启动成功,master是主进程,关闭的时候kill这个进程,其他子进程会自动关掉
打开浏览器http://localhost/ 即可看到nginx的默认欢迎页
Welcome to nginx!