yum安装
# 安装openssl1.0.2只需要使用Ali的base库,如下
[root@CentOs1612 /etc]# cat <<EOF > /etc/yum.repos.d/Ali-base.repo
[Ali-base]
name=Ali-base
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/os/x86_64/
http://mirrors.aliyuncs.com/centos/7/os/x86_64/
gpgcheck=0
enabled=1
EOF
[root@CentOs1612 /root]# yum install -y openssl
# 添加epel.repo,如下
[root@centos1611 /etc]# echo '[Centos7-Ali-epel]
name=Centos7-Ali-epel
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
http://mirrors.aliyuncs.com/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=0' > /etc/yum.repos.d/Centos7-Ali-epel.repo && yum install -y nginx
# 新版的nginx(1.12以上)要升级openssl1.0.2,也可以安装旧版的nginx,命令如下:
[root@centos1611 /etc]# yum install -y http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.10.3-1.el7.ngx.x86_64.rpm
源码编译安装
[root@server nginx-1.8.0]# yum install -y gcc gcc-c++ pcre* openssl* # 安装pcre*以支持rewrite功能
# 安装openssl*以支持ssl
[root@2015 2015.9.11zabbix实验]# file 2015.9.11.1nginx-1.8.0.tar.gz # 以前下载的这个源码包也有点老了,版本是1.8
2015.9.11.1nginx-1.8.0.tar.gz: gzip compressed data, from Unix, last modified: Tue Apr 21 22:12:06 2015
[root@2015 2015.9.11zabbix实验]# ls
~$15.9.10zabbix实验过程.docx 2015.9.11.1nginx-1.8.0.tar.gz 2015.9.11.2nginx安装.mht
2015.9.10zabbix实验过程.docx 2015.9.11.1去nginx官网下载nginx.mht nginx-1.8.0
###在Windows(或Linux)中解压得到nginx-1.8.0目录###
[root@2015 2015.9.11zabbix实验]# cd nginx-1.8.0/
[root@2015 nginx-1.8.0]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-pcre
# --with-http_stub_status_module:支持nginx状态查询
# --with-http_ssl_module:支持https
# --with-http_spdy_module:支持google的spdy,想了解请百度spdy,这个必须有ssl的支持
# --with-pcre:为了支持rewrite重写功能,必须制定pcre
[root@2015 nginx-1.8.0]# make
[root@2015 nginx-1.8.0]# make install
[root@server nginx-1.8.0]# ll /usr/local/nginx/sbin/ # 确定nginx二进制文件的位置. 5.4MB的文件,也算挺大的了
-rwxr-xr-x. 1 root root 5.4M Nov 16 15:12 nginx
[root@2015 nginx-1.8.0]# ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx # 二进制文件加入到PATH路径
[root@2015 nginx-1.8.0]# nginx -h
nginx version: nginx/1.8.0
Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit # 常用,检查*.conf文件是否配置正确
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
# stop,reload可关闭或重新加载nginx
-p prefix : set prefix path (default: /usr/local/nginx/)
-c filename : set configuration file (default: conf/nginx.conf)
# nginx配置文件的默认路径为/usr/local/nginx/conf/nginx.conf
-g directives : set global directives out of configuration file
[root@2015 nginx-1.8.0]# nginx # 启动nginx,其实在启动之前可以nginx -t先测试配置文件的语法是否正确
[root@2015 nginx-1.8.0]# chkconfig --list|grep ngi
[root@2015 nginx-1.8.0]# echo '/usr/local/nginx/sbin/nginx' >> /etc/rc.d/rc.local # 开机启动
[root@2015 nginx-1.8.0]# curl -s http://localhost|grep nginx.com # 用CURL测试WEB站点是否正常。curl -s选项:不显示进度表和错误信息
<a href="http://nginx.com/">nginx.com</a>.</p>