使用nginx有一段时间了,还是有很多东西不懂的,在这里做一下自己学习过程中的一些整理,能使自己得到提升。

1、环境:centos7 1511  最小化安装

2、下载nginx,可以在系统中下载,也可以提前下载好,直接上传到服务器,都是可以的。

[root@bogon ~]# wget -c http://nginx.org/download/nginx-1.14.1.tar.gz

3、安装nginx的依赖环境

这里要重点说明一下,因为我们在编译nginx的时候需要的模块不一样,所需要的依赖包也不一样,这里我接受我使用的依赖,仅供参考

openssl-devel  这个包是https请求的时候要用到的,主要是提供ssl加密,当然其他的nginx模块也有用到这个依赖的,作用差别不大。

pcre  这个包是pcre的正则,是nginx中的rewirte规则会用到的,当然如果你不是用rewirte模块的话,也是可以不用安装的

zlib 这个包是启动压缩传输的时候会用到的,一般也是需要安装的

[root@bogon ~]# yum -y install pcre-devel openssl-devel zlib-devel

当然,这里也是需要安装gcc和gcc-c++编译器的哦

4、编译和安装

解压到指定的目录中

[root@bogon ~]# tar -xf nginx-1.14.1.tar.gz -C /usr/local/src/

查看配置选项

[root@bogon nginx-1.14.1]# ./configure --help

软件配置

[root@bogon nginx-1.14.1]# ./configure --prefix=/usr/local/nginx  --with-http_ssl_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-stream --with-http_stub_status_module

如果只是单纯的配置web服务的话 ,其中的--with-stream是不需要添加的,具体的配置还是需要根据你的业务来决定的。

编译和安装

[root@bogon nginx-1.14.1]# make &&  make install

5、启动服务,并添加到开机自启动

[root@bogon nginx-1.14.1]# cd /usr/local/nginx/sbin/
[root@bogon sbin]# ./nginx 

由于是源码安装,设置开机自启动的话,需要在相应的文件中添加

[root@bogon sbin]# cd /etc/rc.d/
[root@bogon rc.d]# vim rc.local
/usr/local/nginx/sbin/nginx  #添加这一行
[root@bogon rc.d]# chmod +x rc.local

6、查看服务的运行状态

[root@bogon ~]# ps -ef | grep nginx
root      15971      1  0 19:21 ?        00:00:00 nginx: master process ./nginx
nobody    15972  15971  0 19:21 ?        00:00:00 nginx: worker process

完工。。。。。

内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!

相关课程

4278 999.8元 4999元 2折