centos7.2安装nginx-1.10.2

 

官方下载地址:http://nginx.org/en/download.html

参考:http://www.cnblogs.com/rwxwsblog/p/5281756.html

 

官方下载后是源码,需要编译

安装相关编译组件及依赖库:

yum -y install gcc-c++
yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
yum -y install openssl openssl-devel libssl-dev

 

下载并安装:

[root@localhost nginx-1.10.2]# cd /usr/local/
[root@localhost local]# 
[root@localhost local]# wget http://101.96.8.164/nginx.org/download/nginx-1.10.2.tar.gz
[root@localhost local]# tar -zxvf nginx-1.10.2.tar.gz

 

编译:

这里按照参考文章编译完成后不能运行没有sbin目录,直接使用./configure编译完成后可以运行。

--with-http_ssl_module 后面的这个参数生成ssl的支持,否则后面使用https配置不会成功,出现[emerg] the "ssl" parameter requires ngx_http_ssl_module xxxxx
的错误

 

[root@localhost local]# cd nginx-1.10.2
[root@localhost nginx-1.10.2]# ./configure --with-http_ssl_module
xxxxxxxxxxx
[root@localhost nginx-1.10.2]# make
xxxxxxxxxxxx
[root@localhost nginx-1.10.2]# make install
xxxxxxxxxxxx
make[1]: 离开目录“/usr/local/nginx-1.10.2”

 

启动nginx:

[root@localhost nginx-1.10.2]# /usr/local/nginx/sbin/nginx

 

添加开放端口80和443  

[root@localhost nginx-1.10.2]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
success
[root@localhost nginx-1.10.2]# firewall-cmd --zone=public --add-port=443/tcp --permanent
success
[root@localhost nginx-1.10.2]# firewall-cmd --reload
success

 

查看全部已经开放的端口:

[root@localhost nginx-1.10.2]# firewall-cmd --zone=public --list-ports
443/tcp 80/tcp 8080/tcp

 

通过浏览器访问:http://serverip/

可以看到nginx 欢迎页就安装成功了。

Welcome to nginx!

参考: http://nginx.org/en/linux_packages.html#mainline

===============================yum安装============================

本文主要介绍在CentOS7.2下利用yum源安装nginx。

第一步在/etc/yum.repos.d/目录下建立一个nginx.repo软件源配置文件。命令如下: 
# cd /etc/yum.repos.d/ 
# vim ./nginx.repo 

然后填写如下文件内容 
[nginx] 
name=nginx repo 
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ 
gpgcheck=0 
enabled=1

执行vim命令保存文件为nginx.repo完整路径是/etc/yum.repos.d/nginx.repo 
:w nginx.repo

执行yum命令安装nginx 
yum install nginx 

猜你喜欢

转载自youngbrick.iteye.com/blog/2336022