正式开始安装前,编译环境gcc g++ 开发库之类的需要提前装好,这里默认你已经装好。
shell># yum -y install gcc gcc-c++
- 创建www组与www用户
shell># groupadd www shell># useradd -g www -s /usr/sbin/nologin www
- 安装PCRE库(重写rewrite)
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 下载最新的 PCRE 源码包,使用下面命令下载编译和安装 PCRE 包: shell># wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz shell># tar -zxvf pcre-8.40.tar.gz shell># cd pcre-8.40 shell># ./configure && make && make install
- 安装zlib库(gzip压缩)
ftp://ftp.simplesystems.org/pub/png/src/zlib 下载最新的 zlib 源码包 shell>#wget ftp://ftp.simplesystems.org/pub/png/src/zlib/zlib-1.2.11.tar.gz shell>#tar -zxvf zlib-1.2.11.tar.gz shell>#cd zlib-1.2.11 shell>#./configure && make && make install
- 安装ssl(某些vps默认没装ssl)
shell>#wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz shell>#tar -zxvf openssl-1.0.1c.tar.gz shell>#./config && make && make install
- 安装nginx
shell>#wget http://nginx.org/download/nginx-1.6.0.tar.gz shell>#tar -zxvf nginx-1.6.0.tar.gz shell>#cd nginx-1.6.0 shell>#./configure --sbin-path=/usr/local/nginx \ --conf-path=/usr/local/nginx/nginx.conf \ --pid-path=/usr/local/nginx/nginx.pid \ --with-http_ssl_module \ --with-pcre=/home/software/pcre-8.40 \ --with-zlib=/home/software/zlib-1.2.11 \ --with-openssl=/home/software/openssl-1.0.1c shell>#make && make install
- Nginx基本操作
关闭Nginx shell>#ps -ef | grep nginx shell>#kill -quit 进程号 启动Nginx shell>#./nginx -c /usr/local/web/nginx/conf/nginx.conf nginx重启 shell>#./nginx -s reload
- 安装过程报错的解决方案
安装如果报错为Nginx: error while loading shared libraries: libpcre.so.1 具体网站可参考http://www.2cto.com/os/201304/199770.html 找到libpcre.so.1文件路径 shell>#ln -s /lib/libpcre.so.0.0.1 /lib/libpcre.so.1 shell>#ln -s /usr/local/lib/libpcre.so.1 /lib64/
- 开放iptables的80端口
在Linux中设置防火墙,以CentOS为例,打开iptables的配置文件: shell>#vi /etc/sysconfig/iptables 如果没有iptables文件,则将iptables.old复制一份iptables文件 shell>#cp /etc/sysconfig/iptables.old /etc/sysconfig/iptables 通过/etc/init.d/iptables status命令查询是否有打开80端口,如果没有可通过两种方式处理: 方式一: 1.修改vi /etc/sysconfig/iptables命令添加使防火墙开放80端口 -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 2.关闭/开启/重启防火墙 shell>#/etc/init.d/iptables stop #关闭 shell>#/etc/init.d/iptables start #开启 shell>#/etc/init.d/iptables restart #重启 方式二:永久性关闭防火墙 shell>#chkconfig --level 35 iptables off shell>#/etc/init.d/iptables stop shell>#iptables -P INPUT DROP
最后我在浏览器的地址栏中输入:localhost 出现如下图所示表示Nginx安装成功
至此Nginx安装完成。