CentOS 7.2 源码安装Nginx

# uname -r
3.10.0-327.el7.x86_64
# ./configure --prefix=/usr/local/nginx

安装前还是在网上稍微搜集了一些信息,我的CentOS安装在虚拟机上,安装的时候选择的是最小安装,所以编译安装时所需要的一些编译器和依赖库可能没有,所以先来安装这些编译环境。

# yum install gcc gcc-c++ zlib-devel pcre-devel openssl-libs openssl -y

安装完编译环境和依赖库之后再一次检测安装环境并生成Makefile文件,在这一步操作过程可以自定义一些相关参数,比如软件安装位置、配置文件存放位置以及依赖库文件引用路径等等,具体参数说明可以使用./configure --help来查看。

# ./configure --prefix=/usr/local/nginx

出现如图提示表示Makefile文件制作完成,接下来开始准备安装啦!

使用make命令来进行编译,中间会出现一堆的代码o(╯□╰)o

# make

看最后一行,表示编译没有发现问题,成功!!

最后一步,开始使用“make install”执行安装操作。

# make install

安装完成,接下来配置环境变量以后就不用使用绝对路径来操作Nginx来了;

# vim /etc/profile.d/http.sh
1 export PATH=/usr/local/nginx/sbin:$PATH
# source !$

可以使用nginx -h命令来查看相关选项:

# nginx -h
nginx version: nginx/1.10.2
Usage: nginx [-?hvVtTq] [-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
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal    : send signal to a master process: stop, quit, reopen, reload
  -p prefix    : set prefix path (default: /usr/local/nginx/)
  -c filename  : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file

常用的就是-s 后跟stop、reload来关闭和重载nginx,直接运行nginx则启动服务。

接下来就差最后一步就可以访问了,配置大防火墙(*@ο@*) 哇~!

# iptables -A INPUT -d 192.168.30.10 -p tcp --dport 80 -m state NEW -j ACCEPT

使用浏览器输入虚拟机的IP地址,如果不出意外的话会出现如下画面。

成功!!

下面关于Nginx的文章您也可能喜欢,不妨参考下:

Nginx 的详细介绍请点这里
Nginx 的下载地址请点这里

猜你喜欢

转载自www.linuxidc.com/Linux/2017-03/141246.htm