Linux初学(十三)中间件

一、Nginx

简介

Nginx是一个高性能的HTTP和反向代理web服务器

轻量级、高性能

1.1 Nginx安装

方法一:编译安装

  • 依赖:openssl-devel、zlib-devel、ncurses-devel、pcre-devel、gcc、gcc-c++

方法二:yum安装

  • Nginx的rpm包在epel源中

编译安装Nginx

下载位置:https://nginx.org

第一步:下载

html 复制代码
[root@localhost html]# wget http://nginx.org/download/nginx-1.24.0.tar.gz

第二步:安装依赖

html 复制代码
[root@localhost ~]# yum install opensl-devel zlib-devel ncurses-devel pcre-devel gcc gcc-c++ -y

第三步:安装Nginx

html 复制代码
[root@localhost ~]# tar xvf nginx-1.24.0.tar.gz
[root@localhost ~]# cd nginx-1.24.0
[root@localhost nginx-1.24.0]#./configure --prefix=/usr/local/nginx && make && make install

Nginx的目录结构

html 复制代码
[root@localhost ~]# cd /usr/local/nginx
[root@localhost ~]# ls
conf html logs sbin
  • conf:这个目录存放的是Nginx的配置文件
  • html:这个目录是Nginx默认网站的根目录
  • logs:这个是Nginx的日志文件目录
  • sbin:这个是Nginx的启动程序的目录

1.2 启动Nginx

启动程序:

html 复制代码
[root@localhost ~]# cd /usr/local/nginx/sbin/
[root@localhost sbin]# ./nginx
[root@localhost sbin]# lsof -i :80

扩展:重启Nginx

html 复制代码
方法一:
[root@localhost ~]# cd /usr/local/nginx/sbin/
[root@localhost sbin]# ./nginx -s reload

方法二:
先kill -9杀手进程,然后启动

扩展:让Nginx开机自动启动

html 复制代码
[root@localhost ~]# echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.d/rc.local
[root@localhost ~]#chmod +x /etc/rc.d/rc.local

1.3 Nginx的配置文件

配置文件的位置

html 复制代码
yum安装:/etc/nginx/
编译安装:安装位置/conf/

文件名

html 复制代码
nginx.conf

配置文件的基本结构

html 复制代码
全局段:
       可以什么都没有
       可以有

http段: - 虚拟主机段

配置文件的格式

html 复制代码
worker_processes  3;
events {
    worker_connections 1024;
}

http {
    include mime.types
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout  65;

    server {
        listen 80;
        server_name www.web1.com;
        root /usr/local/nginx/html;
        index index.html index.htm;
        access_log logs/host.access.log main;
        error_log logs/host.error.log main;
    }

}

案例:基于nginx发布多个网站

html 复制代码
相关推荐
IT策士16 小时前
Python 中间件系列:文件存储minio操作操
开发语言·python·中间件
驾驭人生17 小时前
企业级微服务基础设施 | Docker Compose 9 大中间件 本地私有仓库 一键部署脚本前言
docker·微服务·中间件
IT策士17 小时前
Python 中间件系列:消息队列 RabbitMQ 操作
python·中间件·rabbitmq
祁_z18 小时前
Pydantic 数据校验 & 限流中间件(限制每个 IP 的请求频率,防止接口被刷爆)
网络协议·tcp/ip·中间件
Betelgeuse7620 小时前
Django 中间件 4 大钩子 & CBV vs FBV 对比实战
python·中间件·django
java资料站1 天前
常用中间件快速搭建
docker·中间件
Java面试题总结2 天前
.NET 8 Web开发入门(三):解构引擎——依赖注入(DI)与中间件管道
前端·中间件·.net
IT策士2 天前
Python 中间件系列:kafka学习
python·中间件·kafka
无风听海2 天前
深入剖析 YARP 的 Transforms:构建灵活的反向代理转换管道
后端·中间件·asp.net
IT策士2 天前
Python 中间件系列:redis 深入浅出
redis·python·中间件