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 复制代码
相关推荐
一只小透明啊啊啊啊4 小时前
Java的中间件
java·开发语言·中间件
R.lin9 小时前
使用注解将日志存入Elasticsearch
java·大数据·后端·elasticsearch·中间件
神工坊14 小时前
仿真科普|CAE技术赋能无人机,低空经济蓄势起飞
中间件·云计算·无人机·云平台·hpc·cae·高性能仿真
shaominjin1232 天前
OpenCV 4.1.2 SDK 静态库作用与功能详解
android·c++·人工智能·opencv·计算机视觉·中间件
信创检测小安3 天前
国产中间件与浏览器选型指南:覆盖政务、金融、电信应用场景
中间件·金融·政务
莫陌尛.3 天前
docker安装中间件
docker·中间件·容器
今天背单词了吗9804 天前
Spring Boot+RabbitMQ 实战:4 种交换机模式(Work/Fanout/Direct/Topic)保姆级实现
java·spring·中间件·rabbitmq·1024程序员节
想睡好5 天前
express中间件(java拦截器)
java·中间件·express
文火冰糖的硅基工坊5 天前
[人工智能-大模型-57]:模型层技术 - 软件开发的不同层面(如底层系统、中间件、应用层等),算法的类型、设计目标和实现方式存在显著差异。
人工智能·算法·中间件
兢兢业业的小白鼠5 天前
Java常用中间件整理讲解——Redis,RabbitMQ
java·中间件·java-rabbitmq·1024程序员节