下载安装包
wget http://nginx.org/download/nginx-1.8.1.tar.gz
安装 gcc
[iyunv@localhost nginx-1.8.1]# yum -y install gcc-c++
安装 pcre pcre-devel
PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。命令:
[iyunv@localhost nginx-1.8.1]# yum -y install pcre-devel
安装 zlib-devel
zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。
[iyunv@localhost nginx-1.8.1]# yum -y install zlib-devel
OpenSSL 安装
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。
[iyunv@localhost nginx-1.8.1]# yum install -y openssl openssl-devel
安装nginx
[iyunv@localhost nginx-1.8.1]# ./configure #默认安装到/usr/local/nginx目录下
[iyunv@localhost nginx-1.8.1]# make #编译
[iyunv@localhost nginx-1.8.1]# make install #安装
启动ngnix
[iyunv@localhost local]# cd /usr/local/nginx/sbin
[iyunv@localhost sbin]# ./nginx #启动命令注意输入的 点和斜杠,如果直接输入 nginx会提示 "bash: nginx: 未找到命令..."
查看nginx进程
[iyunv@localhost sbin]# ps -ef|grep nginx
root 5455 1 0 06:24 ? 00:00:00 nginx: master process ./nginx
nobody 5456 5455 0 06:24 ? 00:00:00 nginx: worker process
root 5500 4179 0 06:26 pts/1 00:00:00 grep --color=auto nginx
在浏览器访问 http://localhost出现welcome界面则安装成功!
nginx常用命令
nginx -t:检查配置文件是否正确。这个命令可以检查nginx.conf配置文件其格式、语法是否正确。如果配置文件存在错误,则会出现相应提示;如果nginx.conf文件正确,也会出现相应的成功提示。
[iyunv@localhost sbin]# ./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 -s reload:重加载/重启nginx——以新的nginx.conf配置文件中的定义。
nginx -s stop:停止nginx。必须有-s参数 |