Linux-----nginx的简介,nginx搭载负载均衡以及nginx部署前后端分离项目

目录

nginx的简介

是什么

nginx的特点以及功能

Nginx负载均衡

下载 

安装 

负载均衡


nginx的简介

是什么

Nginx是一个高性能的开源Web服务器和反向代理服务器。它的设计目标是为了解决C10k问题,即在同一时间内支持上万个并发连接。

Nginx采用事件驱动的异步架构,能够高效地处理大量并发请求,同时占用较少的系统资源。它具有良好的扩展性和高可靠性,广泛应用于大型网站和高负载的Web应用中。

nginx的特点以及功能

  1. 高性能:Nginx采用异步非阻塞的处理方式,可以高效地处理大量并发请求,具有较低的内存消耗和CPU利用率。

  2. 反向代理:Nginx可以作为反向代理服务器,将客户端的请求转发给后端的多个服务器,实现负载均衡和高可用性。

  3. 静态文件服务:Nginx可以快速地提供静态文件的访问,减轻动态应用服务器的负载。

  4. 动态反向代理:Nginx可以通过配置动态反向代理规则,将请求转发给不同的后端服务器,实现灵活的请求处理和应用切换。

  5. SSL/TLS支持:Nginx支持HTTPS协议,并提供了强大的SSL/TLS功能,可以保护网站的安全性。

  6. URL重写和重定向:Nginx支持强大的URL重写和重定向功能,可以通过配置简化URL结构和实现请求的重定向。

  7. 缓存和压缩:Nginx支持静态文件的缓存和内容的压缩,提高网站的性能和传输速度。

 总之,Nginx是一个高性能、可靠性强、功能丰富的Web服务器和反向代理服务器,适用于各种规模的网站和应用场景。它的简单配置和灵活性使得它成为许多开发者和系统管理员的首选。

Nginx负载均衡

下载 

输入命令 :  cd /root/xyh/software  进入到资源文件目录

安装 Nginx 的4个依赖

输入命令 : yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

 

安装完成后进行解压使用

输入命令 :  tar -xvf nginx-1.13.7.tar.gz   ( 解压 Nginx)

 

解压后进入其文件

命令 :  cd nginx-1.13.7  

编译,执行配置: 考虑到后续安装ssl证书 添加两个模块

命令 : ./configure --with-http_stub_status_module --with-http_ssl_module

 

安装 

进行安装

命令 :   make && make install

 

安装完后,进入该目录

输入命令 :  cd /usr/local/nginx

安装完后,进入该目录

输入命令 :  cd /usr/local/nginx

启动前安装 lsof 命令

输入命令 :  yum install -y  lsof

 

设置防火墙 开放 80 端口

输入命令 : firewall-cmd --zone=public --add-port=80/tcp --permanent

更新防火墙的端口并且查看已开放的端口

输入命令 :  firewall-cmd --reload && firewall-cmd --list-port

 

# 启动

命令 :  ./nginx

#查看 

命令 :  lsof -i:80

 

在浏览器中,输入虚拟机【Linux】-Centos的IP地址进行搜索 

 以上就是Nginx 的使用配置并且开启完成了

负载均衡

在资源文件夹中,创建一个tomcat文件夹,来存放Tomcat
输入命令 :  mkdir tomcat

并且将tomcat服务解压到指定目录,刚刚创建的tomcat文件夹中。

输入命令 : tar -xvf apache-tomcat-8.5.tar.gz -C tomcat

 

进入tomcat文件夹中

命令 :  cd /root/xyh/software/tomcat

复制一个tomcat,准备2个tomcat

命令 : cp -r apache-tomcat-8.5.20/ apache-tomcat-8.5.20_8081/

查看命令 : ll

 

将其中的一个tomcat修改端口,避免两个服务同时开启时端口被占用的情况。

命令 :  cd apache-tomcat-8.5.20/conf   ( 进入到tomcat的conf文件中 )

找到server.xml 文件进行修改端口

命令 : vim server.xml   ( 编辑文件修改端口 ) 

 

 

 修改之后的代码

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at
      http://www.apache.org/licenses/LICENSE-2.0
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="8006" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
 
  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>
 
  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">
 
    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->
 
 
    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8081" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
         This connector uses the NIO implementation. The default
         SSLImplementation will depend on the presence of the APR/native
         library and the useOpenSSL attribute of the
         AprLifecycleListener.
         Either JSSE or OpenSSL style configuration may be used regardless of
         the SSLImplementation selected. JSSE style configuration is used below.
    -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true">
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    -->
    <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
         This connector uses the APR/native implementation which always uses
         OpenSSL for TLS.
         Either JSSE or OpenSSL style configuration may be used. OpenSSL style
         configuration is used below.
    -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
               maxThreads="150" SSLEnabled="true" >
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
            <Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
                         certificateFile="conf/localhost-rsa-cert.pem"
                         certificateChainFile="conf/localhost-rsa-chain.pem"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    -->
 
    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />
 
 
    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->
 
    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="localhost">
 
      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->
 
      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>
 
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
 
        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->
 
        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
 
      </Host>
    </Engine>
  </Service>
</Server>

 并且将这个服务器的页面显示内容进行修改,访问时容易分辨是哪个tomcat端口进入的

 在tomcat根目录的webapps中的ROOT目录中,找到index.jsp文件,在MobaXterm工具的左边选中这个文件,右键点击第二个进行打开文件,并且修改编辑文件。

 

修改完之后的代码如下

<%--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at
 
    http://www.apache.org/licenses/LICENSE-2.0
 
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--%>
<%@ page session="false" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy");
request.setAttribute("year", sdf.format(new java.util.Date()));
request.setAttribute("tomcatUrl", "http://tomcat.apache.org/");
request.setAttribute("tomcatDocUrl", "/docs/");
request.setAttribute("tomcatExamplesUrl", "/examples/");
%>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <title><%=request.getServletContext().getServerInfo() %></title>
        <link href="favicon.ico" rel="icon" type="image/x-icon" />
        <link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <link href="tomcat.css" rel="stylesheet" type="text/css" />
    </head>
 
    <body>
    <h1>8081</h1>
       
    </body>
 
</html>

返回到tomcat目录,并且开其两个服务(tomcat) 

命令:  cd apache-tomcat-8.5.20/bin  ( 进入到tomcat的bin目录中 )

 命令:  ./startup.sh   ( 开启服务 )

 

再到 nginx的目录中

命令:  cd /usr/local/nginx

 

并且进入 : sbin目录

输入 :  cd sbin

命令 :  ./nginx -s reload   

注 : 重新开启nginx

 

今天就到这里了!下班下班!!!!!!!!!!!!!!!! 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/114289.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【云原生-K8s】Kubernetes安全组件CIS基准kube-beach安装及使用

基础介绍kube-beach介绍kube-beach 下载百度网盘下载wget下载 kube-beach安装kube-beach使用基础参数配置信息解读示例结果说明 基础介绍 为了保证集群以及容器应用的安全&#xff0c;Kubernetes 提供了多种安全机制&#xff0c;限制容器的行为&#xff0c;减少容器和集群的攻…

身份证二要素核验API:提高身份验证的精确性与效率

前言 在数字时代&#xff0c;身份验证已经成为各行各业的重要环节。无论是金融交易、电子商务还是在线服务&#xff0c;确保用户身份的准确性至关重要。身份证二要素核验API&#xff0c;作为一种先进的技术解决方案&#xff0c;正在逐渐崭露头角&#xff0c;为身份验证带来了精…

el-table中的el-input标签修改值,但界面未更新,解决方法

el-table中的el-input标签修改值&#xff0c;界面未更新 在el-table中的el-input里面写的change事件根本不触发&#xff0c;都不打印&#xff0c;试了网络上各种方法都没用 然后换成input事件&#xff0c;input事件会触发&#xff0c;但界面也未更新。我在触发事件的时候&…

Mac允许任何来源的的安装包进行安装

首先打开终端&#xff0c;开启“任何来源”&#xff0c;执行如下命令&#xff1a; sudo spctl --master-disable 然后回车&#xff0c;继续输入密码&#xff08;密码输入时是不可见的&#xff09;&#xff0c;然后回车。 接着打开【系统偏好设置】&#xff0c;选择【安全性与…

react-router

一、react-router是什么 react-router是一个用于管理React应用程序中路由的库。路由是指确定应用程序如何根据URL路径来渲染不同的组件和页面。使用react-router可以将应用程序的不同页面映射到不同的URL路径&#xff0c;以及在用户导航时动态地加载适当的组件。这样&#xff…

【实战Flask API项目指南】之五 RESTful API设计

实战Flask API项目指南之 RESTful API设计 本系列文章将带你深入探索实战Flask API项目指南&#xff0c;通过跟随小菜的学习之旅&#xff0c;你将逐步掌握 Flask 在实际项目中的应用。让我们一起踏上这个精彩的学习之旅吧&#xff01; 前言 当小菜踏入Flask后端开发的世界时…

sublime怎么调中文?

Sublime Text是一个功能强大的文本编辑器&#xff0c;它被广泛使用于编码过程中。在开发过程中&#xff0c;Sublime Text界面的语言设置通常默认为英语&#xff0c;无法直接输入中文。那么如何调整Sublime Text编辑器的设置&#xff0c;以允许在界面中输入和编辑中文呢&#xf…

嵌入式web boa配置流程详解

boa配置流程详解 前期准备boa介绍操作目的下载boa 配置流程1.解压boa服务器2.配置Makefile3.编译boa服务器4.修改boa配置文件5.增加权限并编译cgi6.测试demo7.错误示例 附录A history附录B boa.conf 前期准备 boa介绍 Boa服务器是一个小巧高效的web服务器&#xff0c;是一个运…

虹科示波器 | 汽车免拆检修 | 2012 款上汽大众帕萨特车 发动机偶尔无法起动

一、故障现象 一辆2012款上汽大众帕萨特车&#xff0c;搭载CFB发动机&#xff0c;累计行驶里程约为12万km。车主反映&#xff0c;将点火开关置于起动挡&#xff0c;偶尔只能听到“咔哒”一声&#xff0c;起动机没有反应&#xff0c;类似蓄电池亏电时起动发动机的现象。为此&…

优思学院|质量管理工作困难重重,为何仍有人乐此不疲?

有一位网友说道&#xff1a;质量管理工作困难重重&#xff0c;为何仍有人乐此不疲&#xff1f;我完全理解他的困惑&#xff0c;质量管理工作的确是个不容易的任务&#xff0c;充满挑战&#xff0c;需要不断的努力和耐心。尽管如此&#xff0c;很多人依然选择从事这个领域的工作…

学习c++的第二天

目录 数据类型 基本数据类型 typedef 声明 枚举类型 类型转换 变量类型 变量定义 变量声明 左值&#xff08;Lvalues&#xff09;和右值&#xff08;Rvalues&#xff09; 变量作用域 数据类型 基本数据类型 C 为程序员提供了种类丰富的内置数据类型和用户自定义的数…

uni-app 应对微信小程序最新隐私协议接口要求的处理方法

这里给大家分享我在网上总结出来的一些知识&#xff0c;希望对大家有所帮助 一&#xff0c;问题起因 最新在开发小程序的时候&#xff0c;调用微信小程序来获取用户信息的时候经常报错一个问题 fail api scope is not declared in the privacy agreement&#xff0c;api更具公告…

Windows Server 2008安装

1.典型 2.稍后安装操作系统 3.Microsoft Windows 4.尽量虚拟机名称也改一下&#xff0c;我忘记改了 5. 默认40G差不多了&#xff0c;不用修改了 6.直接点完成 7.配置处理器和镜像 8.中文简体 9.现在安装 10.第一个就行&#xff08;完全安装&#xff09; 11.我接受&#xff0c…

HarmonyOS数据管理与应用数据持久化(一)

一. 数据管理概述 功能介绍 数据管理为开发者提供数据存储、数据管理能力&#xff0c;比如联系人应用数据可以保存到数据库中&#xff0c;提供数据库的安全、可靠等管理机制。 数据存储&#xff1a;提供通用数据持久化能力&#xff0c;根据数据特点&#xff0c;分为用户首选项、…

设计模式_状态模式

状态模式 介绍 设计模式定义案例问题堆积在哪里解决办法状态模式一个对象 状态可以发生改变 不同的状态又有不同的行为逻辑游戏角色 加载不同的技能 每个技能有不同的&#xff1a;攻击逻辑 攻击范围 动作等等1 状态很多 2 每个状态有自己的属性和逻辑每种状态单独写一个类 角色…

银河麒麟x86版、银河麒麟arm版操作系统编译zlmediakit

脚本 # 安装依赖 gcc-c.x86_64 这个不加的话会有问题 sudo yum -y install gcc gcc-c libssl-dev libsdl-dev libavcodec-dev libavutil-dev ffmpeg git openssl-devel gcc-c.x86_64mkdir -p /home/zenglg cd /home/zenglg git clone --depth 1 https://gitee.com/xia-chu…

7.OsgEarth加载Obj模型

愿你出走半生,归来仍是少年&#xff01; 除了大面积的倾斜摄影的加载&#xff0c;同时还存在单个模型的加载。常用的obj模型作为单体在三维场景中的呈现。 原理类似于6.OsgEarth加载倾斜摄影-CSDN博客中的倾斜加载。 1.代码 通过osg读取文件作为节点添加到GeoTransform节点中&…

探索ChatGPT在学术写作中的应用与心得

随着人工智能的迅猛发展&#xff0c;ChatGPT作为一种强大的自然语言处理模型&#xff0c;逐渐在学术界引起了广泛的关注。本文将探讨ChatGPT在学术写作中的应用&#xff0c;并分享使用ChatGPT进行学术写作时的一些经验和心得。 01 — ChatGPT在学术写作中的应用 1.文献综述和…

Openssl数据安全传输平台019:外联接口类的封装以及动态库的制作 - Bug未解决,感觉不是代码的问题

文章目录 1 外联接口1.1 接口类的封装1.2 共享内存与配置文件 2 json格式配置文件的定义2.1 共享内存中存储的节点结构2.2 服务器端配置文件2.3 客户端配置文件2.4 改进配置文件 3 共享内存类修改4 将接口打包成库(静态/动态)4.1 相关的指令4.1.1 静态库4.1.2 动态库 4.2 外联接…

数据结构之树(图解)

文章目录 前言一、树是什么&#xff1f;二、树的特点三、树的相关概念四、树的表示方法&#xff08;孩子兄弟表示法&#xff09;总结 前言 在学习完线性结构&#xff0c;例如顺序表、链表、栈、队列后&#xff0c;我们要开始学习一个新的数据结构----树 一、树是什么&#xf…
最新文章