nginx软件的编译安装步骤

1.1 检查软件安装的系统环境

[root@web02 conf]# cat /etc/redhat-release
CentOS release 6.8 (Final)
[root@web02 conf]# uname -r
2.6.32-642.el6.x86_64
[root@web02 conf]#

1.2 安装nginx的依赖包(pcre-devel openssl-devel)(一)

 yum install -y pcre-devel  openssl-devel
说明:pcre-devel(支持perl nginx 定义了rewrite正则匹配语法是Perl正则语法)
openssl-devel(支持nginx服务访问,以https方式访问)
注:要统一安装路径:/home/data/tools/  下面

1.3 下载nginx软件(二)    

 mkdir -p /home/data/tools          ###注意下载的路径和安装的路径不能一样,否则会出现错误
 cd /home/data/tools
wget -q http://nginx.org/download/nginx-1.10.2.tar.gz      ##复制链接地址(统一位置进行下载)   

1.4 编译安装软件步骤

1.4.1 解压要编译安装的软件(三)

(解压软件---配置(./configure)---做菜(编译 make)---上菜(安装 make install))
tar xf nginx-1.10.2.tar.gz
cd nginx-1.10.2
ls (里面的内容就是源代码(config readme安装说明)---默认编译会安装到/usr/local目录)

1.4.2 创建web服务程序www用户(四)

 useradd -s /sbin/nologin -M www
 ./configure --prefix=/application/nginx-1.10.2 --user=www --group=www --with-http_stub_status_module  --with-http_ssl_module

--prefix=PATH    指定安装路径

--user=user          指定软件启动后以什么什么身份运行(主运行)

--group=group       指定软件启动后以什么什么身份(属组运行,前提用户必须存在。

--with-http_stub_status_module    nginx的激活状态信息  

查看nginx安装时可以使用哪些配置参数

[root@web01 nginx-1.10.2]# ##进入nginx安装目录路径,查看config 帮助信息
[root@web01 nginx-1.10.2]# cd /home/data/tools/nginx-1.10.2/
[root@web01 nginx-1.10.2]# ls
auto     CHANGES.ru  configure  html     Makefile  objs    src
CHANGES  conf        contrib    LICENSE  man       README
[root@web01 nginx-1.10.2]# ./configure --help
  --help                             print this message
  --prefix=PATH                      set installation prefix
  --sbin-path=PATH                   set nginx binary pathname
  --modules-path=PATH                set modules path
  --conf-path=PATH                   set nginx.conf pathname
  --error-log-path=PATH              set error log pathname
  --pid-path=PATH                    set nginx.pid pathname
  --lock-path=PATH                   set nginx.lock pathname

1.4.3  编译安装

cd /home/data/tools/nginx                    ##进入要编译的文件中
 make
 make install

1.4.4 安装完成一个软件要做一个软链接(六)

ln -s /application/nginx-1.10.2 /application/nginx

ln命令的意义十分深远重大,这可是生产环境的经验

nginx安装路径通过软链接的方式更改为/application/nginx/方便人员使用。

安装时指定版本号路径是为了便于查看区分当前使用的nginx版本,也方便以后升级

nginx软件升级编译成新版本后,删除原来的软链接,在重新建立新的到/application/nginx软链接就好。

程序中如果有引用nginx路径的地方,不需要做任何更改,因为升级后访问路径还是/application/nginx        

1.4.5  启动nginx软件程序进行测试

 [root@web02 sbin]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.10.2/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.10.2/conf/nginx.conf test is successful
[root@web02 sbin]# /application/nginx/sbin/nginx
[root@web02 sbin]#
浏览器访问 10.0.0.7:80
lsof -i:80

至此软件安装完毕。

1.4.6 nginx测试方法

 nginx软件语法检查方法:
 /application/nginx/sbin/nginx -t

 nginx软件访问测试过程:
   curl -v www.baidu.com

 nginx重启方法
/application/nginx/sbin/nginx -s reload

 关闭nginx
/application/nginx/sbin/nginx -s stop

/application/nginx/sbin/nginx  -V                 <--- 查看原有的编译参数信息
nginx version: nginx/1.10.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/application/nginx-1.10.2 --user=www --group=www --with-http_stub_status_module --with-http_ssl_module
原文地址:https://www.cnblogs.com/dadonggg/p/8392155.html