个人使用的是centos7版本
1.首先下载Nginx的Linux版本的安装包,官方网站:http://nginx.org/
2.安装环境,
环境要求是C语言开发
gcc:安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc:yum install gcc-c++
PCRE:PCRE(Perl Compatible RegularExpressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。
yuminstall -y pcre pcre-devel
注:pcre-devel是使用pcre开发的一个二次开发库。nginx也需要此库。
zlib:zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。
yuminstall -y zlib zlib-devel
OpenSSL:OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。 nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。
yum install -y openssl openssl-devel
简单来说,你需要以下几个命令:
yum install gcc-c++
yuminstall -y pcre pcre-devel
yuminstall -y zlib zlib-devel
yuminstall -y openssl openssl-devel
3. 编译及安装
第一步:把nginx的源码包上传至linux服务器
第二步:解压源码包。tar -zxf nginx-1.8.0.tar.gz
第三步:进入nginx-1.8.0文件夹。使用configure命令创建。
参数设置如下:
./configure
第四步:make
第五步:make install
注:安装位置一般默认在/usr/local文件夹下
4.Nginx的启动及关闭()
启动
Nginx:
在nginx目录下有一个sbin目录,sbin目录下有一个nginx可执行程序。
./nginx
关闭Nginx:
关闭命令:相当于找到Nginx进程kill。 ./nginx –s stop
退出命令:等程序执行完毕后关闭,建议使用此命令。./nginx -s quit
重新启动:./nginx –s restart
可以不关闭nginx的情况下更新配置文件:./nginx -s reload
5.访问
http://192.168.82.144(虚拟机的IP地址)
ifconfig查看虚拟机的ip地址
ps aux|grep nginx 查看Nginx进程
6.成功界面
成功界面:
Welcometo nginx!
If yousee this page, the nginx web server is successfully installed and working.Further configuration is required.
Foronline documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thankyou for using nginx.