说明: 这篇博客,主要是补充一下,下面这个博客的,也顺便让自己做一下笔记。最后可以让你轻松安装 nginx 成功

 博客原地址   https://blog.csdn.net/wxyjuly/article/details/79443432

安装

在Centos下,yum源不提供nginx的安装,可以通过切换yum源的方法获取安装。也可以通过直接下载安装包的方法,**以下命令均需root权限执行**:首先安装必要的库(nginx 中gzip模块需要 zlib 库,rewrite模块需要 pcre 库,ssl 功能需要openssl库)。选定**/usr/local**为安装目录,以下具体版本号根据实际改变。

1.安装gcc gcc-c++(如新环境,未安装请先安装)    检查是否安装过 gcc   (gcc -v)

yum install -y gcc gcc-c++

 

2.安装PCRE库

$ cd /usr/local/
$ wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz
$ tar -zxvf pcre-8.33.tar.gz
$ cd pcre-8.33
$ ./configure
$ make && make install


如报错:configure: error: You need a C++ compiler for C++ support
解决:yum install -y gcc gcc-c++

注:如果操作 make && make install 报错,就先去执行  yum install -y gcc gcc-c++,然后再去 ./configure ,再去 make && make install

 

3.安装SSL库

$ 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

 

4.安装zlib库存

$ cd /usr/local/
$ wget http://zlib.net/zlib-1.2.11.tar.gz
$ tar -zxvf zlib-1.2.11.tar.gz
$ cd zlib-1.2.11
$ ./configure
$ make && make instal

 

5.安装nginx

$ 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 --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
$ make && make install

这一步的 make 老是报错,网上找了一下是缺少OpenSSL

yum install openssl openssl-devel

然后再执行

$ ./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
$ make && make install

启动nginx

/usr/local/nginx/sbin/nginx

 

 

然后报了下面这个错,一想原来我开开启着, 80端口,

 

 

关闭就好了。 然后访问

 

如果你还是不能访问,

1、看看你的防火墙是否关闭

2、如果是阿里云,看看你的安全组的80端口是否开启

 

部分命令如下:

重启:  $ /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