在Centos下,yum源不提供nginx的安装,能够经过切换yum源的方法获取安装。也能够经过直接下载安装包的方法,如下命令均需root权限执行:nginx
首先安装必要的库(nginx 中gzip模块须要 zlib 库,rewrite模块须要 pcre 库,ssl 功能须要openssl库)。选定/usr/local为安装目录,如下具体版本号根据实际改变。浏览器
1.安装PCRE库测试
$ cd /usr/local/ $ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz $ tar -zxvf pcre-8.36.tar.gz $ cd pcre-8.36 $ ./configure $ make $ make install
2.安装zlib库.net
$ cd /usr/local/ $ wget http://zlib.net/zlib-1.2.8.tar.gz $ tar -zxvf zlib-1.2.8.tar.gz $ cd zlib-1.2.8 $ ./configure $ make $ make install
3.安装sslcode
$ cd /usr/local/ $ wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz $ tar -zxvf openssl-1.0.1j.tar.gz $ ./config $ make $ make install
4.安装nginxip
$ cd /usr/local/ $ wget http://nginx.org/download/nginx-1.8.0.tar.gz $ tar -zxvf nginx-1.8.0.tar.gz $ cd nginx-1.8.0 $ ./configure --prefix=/usr/local/nginx $ make $ make install
在--prefix后面接如下命令:ssl
--with-pcre=/usr/local/pcre-8.36 指的是pcre-8.36 的源码路径。 --with-zlib=/usr/local/zlib-1.2.8 指的是zlib-1.2.8 的源码路径。
点击此处下载安装脚本get
5.启动源码
$ /usr/local/nginx/sbin/nginx
检查是否启动成功:openssl
打开浏览器访问此机器的 IP,若是浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。
部分命令以下:
重启:
$ /usr/local/nginx/sbin/nginx –s reload
中止:
$ /usr/local/nginx/sbin/nginx –s stop
测试配置文件是否正常:
$ /usr/local/nginx/sbin/nginx –t
强制关闭:
$ pkill nginx
以上安装方法nginx的配置文件位于
/usr/local/nginx/conf/nginx.conf