#Http服务器或代理服务器
官网地址:http://nginx.org
官网下载地址:http://nginx.org/en/download.html

#支持rewrite功能的组件
官网地址:www.pcre.org
开源下载地址:http://sourceforge.net/projects/pcre/files/pcre/

上传nginx-1.5.7.tar.gz到/opt/soft/
上传pcre-8.33.tar.gz到/opt/soft/
上传zlib-1.2.8.tar.gz到/opt/soft/
添加web用户
[root@localhost ~]# groupadd www
[root@localhost ~]# useradd -g www wwwweb

[root@localhost ~]# cd /opt/soft

安装rewrite组件
[root@localhost soft]# tar -zxvf pcre-8.33.tar.gz
[root@localhost soft]# cd pcre-8.33/
[root@localhost pcre-8.33]# ./configure
[root@localhost pcre-8.33]# make && make install
[root@localhost pcre-8.33]# cd ../

安装zlib组件

[root@localhost soft]# tar -zxvf zlib-1.2.8.gz
[root@localhost soft]# cd zlib-1.2.8/
[root@localhost zlib-1.2.8]# ./configure
[root@localhost zlib-1.2.8]# make && make install
[root@localhost zlib-1.2.8]# cd ../

解压安装文件
[root@localhost soft]# tar -xzvf nginx-1.5.7.tar.gz
[root@localhost soft]# cd nginx-1.5.7
编译安装文件
[root@localhost nginx-1.5.7]# ./configure --user=www --group=wwwweb --prefix=/opt/sudytech/nginx1.5.7 --with-http_stub_status_module --with-http_ssl_module
[root@localhost nginx-1.5.7]# make
[root@localhost nginx-1.5.7]# make install

启动服务
[root@localhost conf]# /usr/local/nginx/sbin/nginx

常见错误:
[root@localhost ~]# /opt/sudytech/nginx1.5.7/sbin/nginx 
/opt/sudytech/nginx1.5.7/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

从错误看出是缺少lib文件导致,进一步查看下

[root@localhost ~]# ldd $(which /opt/sudytech/nginx1.5.7/sbin/nginx)
        linux-gate.so.1 =>  (0x00200000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x00ca6000)
        libcrypt.so.1 => /lib/libcrypt.so.1 (0x04e3f000)
        libpcre.so.1 => not found
        libz.so.1 => /usr/lib/libz.so.1 (0x00ccb000)
        libc.so.6 => /lib/libc.so.6 (0x00b2f000)
        /lib/ld-linux.so.2 (0x00b11000)

可以看出 libpcre.so.1 => not found 并没有找到,进入/lib目录中手动链接下

[root@localhost ~]# cd /lib
[root@localhost lib]# ln -s libpcre.so.0.0.1 libpcre.so.1

然后在启动nginx ok 了

[root@localhost lib]# /usr/local/nginx/sbin/nginx

再次遇到错误
[root@localhost lib]# /opt/sudytech/nginx1.5.7/sbin/nginx
nginx: [emerg] getpwnam("www") failed

在启动nginx之前还需要添加www用户组,否则会提示
nginx: [emerg] getpwnam("www") failed

事实上我们已经添加过了
解决方案:
在nginx.conf中,在#user  nobody;下添加
#启动nginx服务的用户与组
user  wwwweb www;
即可

再次启动,OK~!

[root@localhost lib]# /usr/local/nginx/sbin/nginx
[root@localhost lib]# ps -ef |grep nginx
root     18889     1  0 19:01 ?        00:00:00 nginx: master process /opt/sudytech/nginx1.5.7/sbin/nginx
wwwweb   18890 18889  0 19:01 ?        00:00:00 nginx: worker process              
root     18905  8704  0 19:02 pts/2    00:00:00 grep nginx

访问安装服务器ip
http://192.168.100.151/

出现下面内容,即说明安装完成。
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.
Logo

更多推荐