nginx-1.9.9安装配置

转原网址:https://blog.csdn.net/blocalhost/article/details/98503172

在安装nginx前首先要确认系统中安装了gcc、pcre-devel、zlib-devel、openssl-devel。

nginx下载地址:https://nginx.org/download/

下载“nginx-1.9.9.tar.gz”,移动到/usr/local/下。

## 解压
tar -zxvf nginx-1.9.9.tar.gz

##移动
mv nginx-1.9.9 nginx

##进入nginx目录
cd nginx

## 配置,这一步可能会出现各种的错误,在下面会一一列出。
./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx #配置文件目录和二进制脚本目录
 

make && make install

nginx #启动nginx

nginx -s stop #关闭

nginx -s reload #重新加载

ps -ef grep | nginx #查看nginx进程

错误信息:

checking for OS
+ Linux 3.10.0-327.el7.x86_64 x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found

解决方法:安装gcc

yum -y install gcc
错误信息:

./configure: error: the HTTP rewrite module requires the PCRE library.

解决方法:安装pcre-devel

yum install pcre-devel
错误信息:

./configure: error: the HTTP gzip module requires the zlib library.

解决方法:安装zlib-devel

yum install zlib-devel
 

再次执行“./configure --prefix=/usr/local/nginx”

正确的结果如下:

    

OK,现在可以执行make 了。 如果你想使用openssl 功能,sha1 功能就需要安装openssl ,sha1。

yum -y install openssl openssl-devel
开启ssl 模块

./configure --with-http_ssl_module
   

执行make、make install命令

测试是否安装成功

./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

启动nginx 

cd /usr/local/nginx/sbin
./nginx //启动nginx
在浏览器中输入服务器的ip地址,如:192.168.1.12

很不幸,打不开链接。下面进行原因排查:

    

    

说明服务器的80端口是打不开的。

因为我使用的linux系统版本是CentOS7,所以可以在服务器中执行如下命令来验证》》

firewall-cmd --query-port=80/tcp
    

显然80端口没有开启。

下面我们开启80端口:

    

刷新浏览器

    

====================== 分割线 ====================

配置完毕!
————————————————
版权声明:本文为CSDN博主「localhostAND」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/blocalhost/article/details/98503172

原文地址:https://www.cnblogs.com/zhao907/p/14621962.html