littlewrong

nginx(编译安装)-自定义安装路径

安装路径:/application/nginx-1.12.0

1.前期准备

安装编译需要的gcc和gcc-c++

yum install -y gcc gcc-c++

nginx依赖

pcre-devel、openssl-devel、zlib-devel

yum install -y pcre pcre-devel openssl openssl-devel zlib zlib-devel

yum -y install patch

创建用户nginx,以该用户的身份执行nginx

useradd -s /bin/false -M nginx

下载nginx源码包并解压到当前目录

mkdir /application

cd /application

CentOS7

--wget http://nginx.org/download/nginx-1.12.0.tar.gz

tar -zxf nginx-1.12.0.tar.gz

mv nginx-1.12.0 nginx_src

CentOS8

wget http://nginx.org/download/nginx-1.19.1.tar.gz

tar -zxf nginx-1.19.1.tar.gz

mv nginx-1.19.1 nginx_src

2.nginx编译安装

生成Makefile文件

cd nginx_src

./configure --user=nginx --group=nginx --prefix=/application/nginx/ --with-http_v2_module --with-http_ssl_module --with-http_sub_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre

编译源代码并安装

make && make install

 

3.后期结尾

添加环境变量

创建nginx命令软链接到环境变量

ln -s /application/nginx/sbin/* /usr/local/sbin/

ln -s /application/nginx/sbin/* /usr/local/sbin/

4.配置nginx开启健康检查

下载模块

nginx -s stop

cd /application

mkdir nginx_patch

cd /applicaton/nginx_patch
wget https://codeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master
unzip master
cd /application/nginx_src/src

打补丁

patch -p1 < /application/nginx_patch/nginx_upstream_check_module-master/check_1.11.5+.patch

预编译

cd /application/nginx_src
./configure --prefix=/application/nginx/ --with-http_v2_module --with-http_ssl_module --with-http_sub_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --user=nobody --group=nobody --add-module=/application/nginx_patch/nginx_upstream_check_module-master/

编译(注意只make)
make

cp /application/nginx_src/objs/nginx  /application/nginx/sbin/nginx

nginx -t

配置文件
upstream xxxxxx
{
server 172.17.1.164:8080;
server 172.17.3.164:8080;
check interval=2000 rise=2 fall=2 timeout=1000 type=http;

# check_http_send "GET /HM/M_Main/Frame/Login HTTP/1.0\r\n\r\n";

}

其中参数的定义如下:

interval:检查的周期

fall:允许的检查失败次数,若失败次数超过该值,则后端被标记为"down"。

rise:检查的成功次数达到该值,则后端被标记为“up”。

timeout:检查的超时时间。

type:后端检查的协议类型。


开启后端存活状态页面,便于查看后端状态。

location /status {
check_status;
access_log off;
#allow IP;
#deny all
}

查看健康状态
http://xxx.xxx.xxx.xxx/status

5.常用命令

检查配置文件

nginx -t

指定其他配置文件启动nginx

nginx -c /application/nginx/conf/nginx.conf

启动nginx

nginx

停止nginx

nginx -s stop

重启nginx

nginx -s reload

参数解释

-s stop 快速停止nginx

-s quit 平滑停止nginx

-s reopen 重新打开日志文件

-s reload 平滑重载所有配置

 

6.目录介绍

 [root@www nginx]# tree

.

├── conf  #配置文件目录

│   ├── fastcgi.conf

│   ├── fastcgi.conf.default

│   ├── fastcgi_params

│   ├── fastcgi_params.default  #fastcgi *配合php

│   ├── koi-utf

│   ├── koi-win

│   ├── mime.types  #mime 媒体类型

│   ├── mime.types.default

│   ├── nginx.conf  #nginx主配置文件

│   ├── nginx.conf.default

│   ├── scgi_params

│   ├── scgi_params.default

│   ├── uwsgi_params

│   ├── uwsgi_params.default

│   └── win-utf

├── html  #默认站点目录

│   ├── 50x.html

│   └── index.html

├── logs  #访问日志、错误日志、pid文件目录

│   ├── access.log  #访问日志

│   ├── error.log  #错误日志

│   └── nginx.pid  #pid文件

└── sbin  #命令目录

└── nginx  #nginx命令文件

分类:

技术点:

相关文章:

  • 2021-09-19
  • 2021-10-18
  • 2022-12-23
  • 2021-06-13
  • 2021-06-07
  • 2022-01-23
  • 2021-05-12
  • 2021-12-12
猜你喜欢
  • 2022-01-01
  • 2021-07-17
  • 2021-11-28
  • 2021-09-10
  • 2021-04-14
  • 2021-05-29
相关资源
相似解决方案