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 复制代码
相关推荐
陌殇殇20 小时前
004 Kafka异常处理
中间件·kafka·springboot
Albert Tan1 天前
Oracle Fusion Middleware 12C安装 - 呆瓜式
oracle·中间件·数据库架构
m0_748254883 天前
docker离线安装及部署各类中间件(x86系统架构)
docker·中间件·系统架构
YGGP4 天前
【Gee】Day5:中间件
中间件·golang
jingwang-cs5 天前
内外网隔离文件传输解决方案|系统与钉钉集成+等保合规,安全提升70%
安全·中间件·钉钉·安全架构
WeiLai11125 天前
面试基础--微服务架构:如何拆分微服务、数据一致性、服务调用
java·分布式·后端·微服务·中间件·面试·架构
web135085886355 天前
全面指南:使用JMeter进行性能压测与性能优化(中间件压测、数据库压测、分布式集群压测、调优)
jmeter·中间件·性能优化
带娃的IT创业者6 天前
《Python实战进阶》专栏 No2: Flask 中间件与请求钩子的应用
python·中间件·flask
HeartRaindj6 天前
【中间件开发】kafka使用场景与设计原理
分布式·中间件·kafka
令狐掌门6 天前
C++中间件DDS介绍
c++·中间件·c++ dds