一、安装在centos下,yum源不提供Nginx的安装,可以通过切换yum源的方法获取安装 。也可以通过直接下载安装包的方法,**以下命令均需root权限执行**:
首先安装必要的库(nginx 中gzip模块需要 zlib 库,rewrite模块需要 pcre 库,ssl 功能需要openssl库) 。选定**/usr/local**为安装目录,以下具体版本号根据实际改变 。
1.1 安装gcc gcc-c++(如新环境,未安装请先安装)
- 1.1 $ yum install -y gcc gcc-c++
- $ cd /usr/local/
- $ wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz
- $ tar -zxvf pcre-8.36.tar.gz
- $ cd pcre-8.36
- $ ./configure
- $ make && make install
- 如报错:configure: error: You need a C++ compiler for C++ support
- 解决:yum install -y gcc gcc-c++
- $ cd /usr/local/
- $ wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz
- $ tar -zxvf openssl-1.0.1j.tar.gz
- $ cd openssl-1.0.1j
- $ ./config
- $ make && make install
$ wget http://zlib.net/zlib-1.2.11.tar.gz
$ tar -zxvf zlib-1.2.11.tar.gz
$ ./configure
$ make && make install
1.5.安装nginx
- 5.1 $ cd /usr/local/
1.5.3 $ tar -zxvf nginx-1.8.0.tar.gz
1.5.4 $ cd nginx-1.8.0
1.5.5 $ ./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module
1.5.6 (注: --with-http_ssl_module:这个不加后面在nginx.conf配置ssl:on后,启动会报nginx: [emerg] unknown directive "ssl" in /opt/nginx/conf/nginx.conf 异常)
1.5.7 $ make && make install
1.5.8 时提示以下错误:
./configure: error: SSL modules require the OpenSSL library.
支持此命令:
yum -y install openssl openssl-devel
1.5.9 报错:./configure: error: the HTTP gzip module requires the zlib library
在–prefix后面接以下命令:
--with-pcre=/usr/local/pcre-8.36 指的是pcre-8.36 的源码路径 。--with-zlib=/usr/local/zlib-1.2.8 指的是zlib-1.2.8 的源码路径 。
1.6.启动$ /usr/local/nginx/sbin/nginx检查是否启动成功:
打开浏览器访问此机器的 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
1.7配置以上安装方法nginx的配置文件位于
推荐阅读
- 金山毒霸捆绑安装软件被起诉 金山毒霸杀毒软件
- 教你如何安装网络摄像机拾音器,图文教程
- SUV要不要安装行李架?安装后带来哪些问题又该注意些什么
- 手机QQ安装包居然快900MB,真就塞了个虚幻引擎?
- 网络摄像机现场安装施工中需要注意的问题
- 使用Nginx、Nginx Plus防止服务器DDoS攻击
- SecureCRT安装及破解
- 水龙头的结构与原理 水龙头安装
- 马桶盖的使用 马桶盖有几种安装样式
- 教你在 CentOS 7 下编译安装 Python 3.7 与 Python 2.7.5 共存
