0
点赞
收藏
分享

微信扫一扫

01Nginx 介绍 安装

海牙秋天 2022-03-11 阅读 85

目录

一、Nginx介绍

1.1引言

1.2Nginx的特点

二、Nginx安装

windows下安装

1、下载nginx

​​2、启动nginx

3、检查nginx是否启动成功

​​

 4、关闭nginx

 linux下安装

1、安装gcc

2、PCRE pcre-devel 安装

3、zlib 安装

4、OpenSSL 安装

5、下载安装包

6、解压

7、配置

8.启动

三、Nginx核心配置文件  nginx.conf


一、Nginx介绍

1.1引言

为什么要学习Nginx

问题1:客户端到底要将请求发送给哪台服务器。

问题2:如果所有客户端的请求都发送给了服务器1。

问题3:客户端发送的请求可能是申请动态资源的,也有申请静态资源。

1.2Nginx的特点

  1. 稳定性能强。7*24 小时不间断运行
  2. Nginx提供了非诚丰富的配置实例
  3. 占用内存小,并发能力强   50,000 个并发  tomcat 1500

二、Nginx安装

windows下安装

1、下载nginx

 nginx: download 下载稳定版本。
下载后解压,解压后如下:

2、启动nginx

有很多种方法启动nginx

(1)直接双击nginx.exe,双击后一个黑色的弹窗一闪而过

(2)打开cmd命令窗口,切换到nginx解压目录下,输入命令 nginx.exe ,回车即可

3、检查nginx是否启动成功

直接在浏览器地址栏输入网址 http://localhost:80 回车,出现以下页面说明启动成功!

 4、关闭nginx

如果使用cmd命令窗口启动nginx, 关闭cmd窗口是不能结束nginx进程的,可使用两种方法关闭nginx

(1)输入nginx命令 nginx -s stop(快速停止nginx) 或 nginx -s quit(完整有序的停止nginx)

(2)使用taskkill taskkill /f /t /im nginx.exe

taskkill是用来终止进程的,
/f是强制终止 .
/t终止指定的进程和任何由此启动的子进程。
/im示指定的进程名称 .

 linux下安装

1、安装gcc

安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:

  1. yum install gcc-c++

2、PCRE pcre-devel 安装

PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。命令:

  1. yum install -y pcre pcre-devel

3、zlib 安装

zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。

  1. yum install -y zlib zlib-devel

4、OpenSSL 安装


OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。

  1. yum install -y openssl openssl-devel

5、下载安装包

手动下载.tar.gz安装包,地址:nginx: download

下载完毕上传到服务器上 /root

6、解压

  1. tar -zxvf nginx-1.18.0.tar.gz
  2. cd nginx-1.18.0

7、配置

使用默认配置,在nginx根目录下执行

./configure
make
make install

查找安装路径: whereis nginx

8.启动

三、Nginx核心配置文件  nginx.conf

worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

# 以上统称为全局快
# worker_processes 的数值越大,Nginx的并发能力就越强
# error_log 代表Nginx的错误日志的存放位置
# pid 不用关注 是Nginx运行的标识

events {
    worker_connections  1024;
}

# events 快
# worker_connections 的数值越大,Nginx并发能力越强

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;

        }
		# location 快
		# root 将接收到的请求根据 html 去查找静态资源
		# index 默认的去上述的路径中找到 index.html 或者 index.htm

        【include /etc/nginx/conf.d/*.conf]】
    }
# server 块
# listen 代表Nginx监听的端口号
# localhost 代表Nginx接收请求的ip
}

# http 快
# include 代表引入一个外部的文件 -> mime.types 中存放这大量的媒体类型
【# include /etc/nginx/conf.d/*.conf -> 引入了 conf.d目录下得以.conf为结尾的配置文件】
举报

相关推荐

0 条评论