Exploring
首页
  • Java

    • 面向对象的思想OOP
    • 浅谈Java反射原理
    • endorsed覆盖JDK中的类
  • 认证与授权

    • LDAP概念和原理介绍
    • OAuth2介绍
  • Impala

    • Impala 介绍
  • MySQL

    • 关于MySQL的一些面试题
    • 解决MySQL不到中文数据
    • 数据库之事务与实现原理
  • Oracle

    • oracle的表空间,用户管理,表操作,函数
    • oracle的查询、视图、索引
    • plsql简单入门
  • Redis

    • 数据类型详解
    • 跳越表
    • 数据持久化的两种方式
  • 共识算法

    • gossip
  • RPC

    • GRPC初识与快速入门
    • ProtocolBuffer基本语法
  • RabbitMQ

    • RabbitMQ入门程序之HelloWorld
    • RabbitMQ之工作模式
  • Zookeeper

    • Zookeeper一文入门
  • Docker

    • Docker入门初体验
  • Maven

    • 把自己的包到Maven中央仓库
    • Maven之自定义插件
  • Nginx

    • nginx的安装
    • nginx的配置文件
    • nignx 的变量
  • Tomcat

    • Servlet3通过SPI进行注册组件
  • Vagrant

    • vagrant 初始化
    • vagrant 常用配置
    • vagrant 自己制作 box
  • Linux

    • 启动方式 Systemd
    • 后台服务
    • 防火墙与 Iptables
  • 设计模式

    • 设计模式-代理
    • 设计模式-单例模式
    • 设计模式-迭代器
  • 分布式

    • CAP 理论
  • 数据结构

    • 数据结构之堆Heap
    • 数据结构之哈希表
    • 数据结构之队列
  • 计算机网络

    • HTTP与HTTPS详解
    • 浅谈DNS协议
    • ISP中的网络层
  • 算法

    • 常用查找算法及Java实现
    • 常用排序算法及Java实现
    • 迪杰斯特拉算法
  • 操作系统

    • 操作系统之进程调度算法
    • 操作系统之进程通讯IPC
    • 操作系统之内存管理
  • 抓包

    • 生成安卓系统证书
  • 加解密

    • 常见加密算法
    • 公开秘钥基础知识
    • RSA 解析
  • Windows

    • scoop 包管理
    • windows-terminal 配置
    • 增强 PowerShell
归档
Github (opens new window)
首页
  • Java

    • 面向对象的思想OOP
    • 浅谈Java反射原理
    • endorsed覆盖JDK中的类
  • 认证与授权

    • LDAP概念和原理介绍
    • OAuth2介绍
  • Impala

    • Impala 介绍
  • MySQL

    • 关于MySQL的一些面试题
    • 解决MySQL不到中文数据
    • 数据库之事务与实现原理
  • Oracle

    • oracle的表空间,用户管理,表操作,函数
    • oracle的查询、视图、索引
    • plsql简单入门
  • Redis

    • 数据类型详解
    • 跳越表
    • 数据持久化的两种方式
  • 共识算法

    • gossip
  • RPC

    • GRPC初识与快速入门
    • ProtocolBuffer基本语法
  • RabbitMQ

    • RabbitMQ入门程序之HelloWorld
    • RabbitMQ之工作模式
  • Zookeeper

    • Zookeeper一文入门
  • Docker

    • Docker入门初体验
  • Maven

    • 把自己的包到Maven中央仓库
    • Maven之自定义插件
  • Nginx

    • nginx的安装
    • nginx的配置文件
    • nignx 的变量
  • Tomcat

    • Servlet3通过SPI进行注册组件
  • Vagrant

    • vagrant 初始化
    • vagrant 常用配置
    • vagrant 自己制作 box
  • Linux

    • 启动方式 Systemd
    • 后台服务
    • 防火墙与 Iptables
  • 设计模式

    • 设计模式-代理
    • 设计模式-单例模式
    • 设计模式-迭代器
  • 分布式

    • CAP 理论
  • 数据结构

    • 数据结构之堆Heap
    • 数据结构之哈希表
    • 数据结构之队列
  • 计算机网络

    • HTTP与HTTPS详解
    • 浅谈DNS协议
    • ISP中的网络层
  • 算法

    • 常用查找算法及Java实现
    • 常用排序算法及Java实现
    • 迪杰斯特拉算法
  • 操作系统

    • 操作系统之进程调度算法
    • 操作系统之进程通讯IPC
    • 操作系统之内存管理
  • 抓包

    • 生成安卓系统证书
  • 加解密

    • 常见加密算法
    • 公开秘钥基础知识
    • RSA 解析
  • Windows

    • scoop 包管理
    • windows-terminal 配置
    • 增强 PowerShell
归档
Github (opens new window)
  • Docker

  • Maven

  • Nginx

    • nginx的作用
      • yum 方式
        • 安装
        • 使用
      • 编译安装
        • 下载源码包
        • 解压源码包
        • 配置
        • 安装
        • 配置服务
    • nginx的配置文件
    • nignx 的变量
    • location配置详解
    • nginx的map模块
    • nginx的日志模块
    • 反向代理
    • 负载均衡
    • 高可用
  • Tomcat

  • Vagrant

  • Linux

  • DevOps
  • Nginx
unclezs
2021-03-12
0
目录

nginx的作用

在 CentOS 上安装

其他版本可见:http://nginx.org/en/linux_packages.html

# yum 方式

# 安装

安装必备软件包

sudo yum install yum-utils
1

增加 nginx 的 yum 仓库

vim /etc/yum.repos.d/nginx.repo 

-----------------------
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

如果想切换为 mainline 版本的可以使用

sudo yum-config-manager --enable nginx-mainline
1

然后就是一键安装了

sudo yum -y install nginx 
1

# 使用

systemctl cat nginx

----------------
# /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /var/run/nginx.pid)"
ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/nginx.pid)"

[Install]
WantedBy=multi-user.target
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

可以看到一些默认配置

  • 配置文件默认在 /etc/nginx/nginx.conf
  • 可执行文件在 /usr/sbin/nginx

当然后续使用也可以直接命令,已经加入了 PATH

nginx -h

--------------
nginx version: nginx/1.22.0
Usage: nginx [-?hvVtTq] [-s signal] [-p prefix]
             [-e filename] [-c filename] [-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: /etc/nginx/)
  -e filename   : set error log file (default: /var/log/nginx/error.log)
  -c filename   : set configuration file (default: /etc/nginx/nginx.conf)
  -g directives : set global directives out of configuration file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# 编译安装

# 下载源码包

  • 在 nginx 官网 (opens new window) 下载源码包
  • 在 pcre2 github (opens new window)下载用于正则匹配的 pcre 包
  • 在 zlib 官网 (opens new window) 下载用于 gzip 压缩的 zlib 包
wget http://nginx.org/download/nginx-1.21.6.tar.gz

# pcre2 用于正则
wget https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.40/pcre2-10.40.tar.gz

# zlib 用于开启 gzip
wget http://zlib.net/zlib-1.2.12.tar.gz
1
2
3
4
5
6
7

# 解压源码包

tar -zxvf nginx-1.21.6.tar.gz

tar -zxvf pcre2-10.40.tar.gz

# 查看目录结构
ll
-------------
drwxr-xr-x. 8 1001 1001  158 Jan 25 15:04 nginx-1.21.6
drwxr-xr-x. 7 1169 1169 4.0K Apr 15 15:51 pcre2-10.40
drwxr-xr-x. 14  501 games 4.0K Mar 27 23:39 zlib-1.2.12
1
2
3
4
5
6
7
8
9
10

# 配置

  • --prefix 最终的安装位置,默认/usr/local/nginx
  • --sbin-path 可执行文件位置
  • --conf-path 默认配置文件位置
  • --pid-path pid 文件位置
  • --with-http_ssl_module 开启 SSL
  • --with-pcre 正则包 pcre 位置,可选
  • --with-zlib 压缩工具 zlib 包位置,可选
cd nginx-1.21.6
# 开始配置
./configure \
    --sbin-path=/usr/local/nginx/nginx \
    --conf-path=/usr/local/nginx/nginx.conf \
    --pid-path=/usr/local/nginx/nginx.pid \
    --with-http_ssl_module \
    --with-pcre=../pcre2-10.40 \
    --with-zlib=../zlib-1.2.12 
    
-------------------------------------------
Configuration summary
  + using PCRE2 library: ../pcre2-10.40
  + using system OpenSSL library
  + using zlib library: ../zlib-1.2.12

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx"
  nginx configuration file: "/usr/local/nginx/nginx.conf"
  nginx pid file: "/usr/local/nginx/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

# 安装

make

# 不会自动添加 PATH
/usr/local/nginx/nginx -h

# 创建链接方便直接 nginx 调用
ln -s /usr/local/nginx/nginx /usr/sbin/nginx
1
2
3
4
5
6
7

# 配置服务

# 开启守护进程

vim /usr/local/nginx/nginx.conf
-------
# 增加
daemon     on;
pid        /var/run/nginx.pid;
1
2
3
4
5

# 配置服务

vim /etc/systemd/system/nginx.service

---------------------
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStart=/usr/sbin/nginx -c /usr/local/nginx/nginx.conf
ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /var/run/nginx.pid)"
ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/nginx.pid)"

[Install]
WantedBy=multi-user.target
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

然后直接可以通过下面命令启动了

systemctl start nginx 
1

开机自启

systemctl enable nginx
1
在 GitHub 编辑此页 (opens new window)
上次更新: 2024/02/25, 12:11:11
Maven之自定义插件
nginx的配置文件

← Maven之自定义插件 nginx的配置文件→

Theme by Vdoing | Copyright © 2018-2024 unclezs
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式