目錄
nginx的簡(jiǎn)介
是什么
nginx的特點(diǎn)以及功能
Nginx負(fù)載均衡
下載?
安裝?
負(fù)載均衡
nginx的簡(jiǎn)介
是什么
Nginx是一個(gè)高性能的開源Web服務(wù)器和反向代理服務(wù)器。它的設(shè)計(jì)目標(biāo)是為了解決C10k問題,即在同一時(shí)間內(nèi)支持上萬(wàn)個(gè)并發(fā)連接。
Nginx采用事件驅(qū)動(dòng)的異步架構(gòu),能夠高效地處理大量并發(fā)請(qǐng)求,同時(shí)占用較少的系統(tǒng)資源。它具有良好的擴(kuò)展性和高可靠性,廣泛應(yīng)用于大型網(wǎng)站和高負(fù)載的Web應(yīng)用中。
nginx的特點(diǎn)以及功能
高性能:Nginx采用異步非阻塞的處理方式,可以高效地處理大量并發(fā)請(qǐng)求,具有較低的內(nèi)存消耗和CPU利用率。
反向代理:Nginx可以作為反向代理服務(wù)器,將客戶端的請(qǐng)求轉(zhuǎn)發(fā)給后端的多個(gè)服務(wù)器,實(shí)現(xiàn)負(fù)載均衡和高可用性。
靜態(tài)文件服務(wù):Nginx可以快速地提供靜態(tài)文件的訪問,減輕動(dòng)態(tài)應(yīng)用服務(wù)器的負(fù)載。
動(dòng)態(tài)反向代理:Nginx可以通過配置動(dòng)態(tài)反向代理規(guī)則,將請(qǐng)求轉(zhuǎn)發(fā)給不同的后端服務(wù)器,實(shí)現(xiàn)靈活的請(qǐng)求處理和應(yīng)用切換。
SSL/TLS支持:Nginx支持HTTPS協(xié)議,并提供了強(qiáng)大的SSL/TLS功能,可以保護(hù)網(wǎng)站的安全性。
URL重寫和重定向:Nginx支持強(qiáng)大的URL重寫和重定向功能,可以通過配置簡(jiǎn)化URL結(jié)構(gòu)和實(shí)現(xiàn)請(qǐng)求的重定向。
緩存和壓縮:Nginx支持靜態(tài)文件的緩存和內(nèi)容的壓縮,提高網(wǎng)站的性能和傳輸速度。
?總之,Nginx是一個(gè)高性能、可靠性強(qiáng)、功能豐富的Web服務(wù)器和反向代理服務(wù)器,適用于各種規(guī)模的網(wǎng)站和應(yīng)用場(chǎng)景。它的簡(jiǎn)單配置和靈活性使得它成為許多開發(fā)者和系統(tǒng)管理員的首選。
Nginx負(fù)載均衡
下載?
輸入命令 :??cd /root/xyh/software? 進(jìn)入到資源文件目錄
安裝?Nginx?的4個(gè)依賴
輸入命令 :?yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
?
安裝完成后進(jìn)行解壓使用
輸入命令 :??tar -xvf nginx-1.13.7.tar.gz? ?( 解壓?Nginx)
?
解壓后進(jìn)入其文件
命令 :??cd nginx-1.13.7??
編譯,執(zhí)行配置: 考慮到后續(xù)安裝ssl證書 添加兩個(gè)模塊
命令 :?./configure --with-http_stub_status_module --with-http_ssl_module
?
安裝?
進(jìn)行安裝
命令 :???make && make install
?
安裝完后,進(jìn)入該目錄
輸入命令 :??cd /usr/local/nginx
安裝完后,進(jìn)入該目錄
輸入命令 :??cd /usr/local/nginx
啟動(dòng)前安裝?lsof?命令
輸入命令 :??yum install -y ?lsof
?
設(shè)置防火墻 開放 80 端口
輸入命令 :?firewall-cmd --zone=public --add-port=80/tcp --permanent
更新防火墻的端口并且查看已開放的端口
輸入命令 :??firewall-cmd --reload && firewall-cmd --list-port
?
# 啟動(dòng)
命令 :??./nginx
#查看?
命令 :??lsof -i:80
?
在瀏覽器中,輸入虛擬機(jī)【Linux】-Centos的IP地址進(jìn)行搜索?
?以上就是Nginx?的使用配置并且開啟完成了
負(fù)載均衡
在資源文件夾中,創(chuàng)建一個(gè)tomcat文件夾,來(lái)存放Tomcat
輸入命令 :??mkdir tomcat并且將tomcat服務(wù)解壓到指定目錄,剛剛創(chuàng)建的tomcat文件夾中。
輸入命令 :?tar -xvf apache-tomcat-8.5.tar.gz -C tomcat
?
進(jìn)入tomcat文件夾中
命令 :??cd /root/xyh/software/tomcat
復(fù)制一個(gè)tomcat,準(zhǔn)備2個(gè)tomcat
命令 :?cp -r apache-tomcat-8.5.20/ apache-tomcat-8.5.20_8081/
查看命令 :?ll
?
將其中的一個(gè)tomcat修改端口,避免兩個(gè)服務(wù)同時(shí)開啟時(shí)端口被占用的情況。
命令 :??cd apache-tomcat-8.5.20/conf? ?( 進(jìn)入到tomcat的conf文件中 )
找到server.xml 文件進(jìn)行修改端口
命令 :?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 "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
?并且將這個(gè)服務(wù)器的頁(yè)面顯示內(nèi)容進(jìn)行修改,訪問時(shí)容易分辨是哪個(gè)tomcat端口進(jìn)入的
?在tomcat根目錄的webapps中的ROOT目錄中,找到index.jsp文件,在MobaXterm工具的左邊選中這個(gè)文件,右鍵點(diǎn)擊第二個(gè)進(jìn)行打開文件,并且修改編輯文件。
?
修改完之后的代碼如下
<%--
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目錄,并且開其兩個(gè)服務(wù)(tomcat)?
命令:??cd apache-tomcat-8.5.20/bin??( 進(jìn)入到tomcat的bin目錄中?)
?命令:??./startup.sh? ?( 開啟服務(wù) )
?
再到?nginx的目錄中
命令:? cd /usr/local/nginx
?
并且進(jìn)入 : sbin目錄
輸入 :??cd sbin
命令 :??./nginx -s reload? ?
注 : 重新開啟nginx
?文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-741691.html
今天就到這里了!下班下班?。。。。。。。。。。。。。。。?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-741691.html
到了這里,關(guān)于Linux-----nginx的簡(jiǎn)介,nginx搭載負(fù)載均衡以及nginx部署前后端分離項(xiàng)目的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!