優(yōu)化nginx.conf
創(chuàng)新互聯(lián)于2013年開(kāi)始,先為嫩江等服務(wù)建站,嫩江等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為嫩江企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。
全局并發(fā)量
http{
版本號(hào)
tcp delay
keepalive
gzip length
gzip types
client head buffer 1k
cache
客戶端瀏覽器緩存:
location \.(jpj|flv|pdf)
expires 30d;
error_page 400 401 402 405 /e.html
error_page 414 /b.html
_________________________________________________________________________________________________________________________________________________________
LNMP (linux nginx MySQL php)
LAMP (linux apache mysql php)
LTMJ (linux tomcat mysql java )
Tomcat--》java
安裝java 解包tomcat庫(kù)文件 打開(kāi)服務(wù) 端口號(hào)是8080
[root@web1 ~]# tar -zxf lnmp_soft-2016-8-9.tar.gz
[root@web1 ~]# cd lnmp_soft
[root@web1 lnmp_soft]# rpm -ivh jdk-8u77-linux-x64.rpm
[root@web1 lnmp_soft]# java -version
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)
[root@web1 lnmp_soft]#
[root@web1 lnmp_soft]# tar -zxf apache-tomcat-8.0.30.tar.gz
[root@web1 lnmp_soft]# mv apache-tomcat-8.0.30 /usr/local/tomcat (tomcat是jave寫的代碼,想要跑它只要電腦里有一個(gè)jave,tomcat里面很多庫(kù)文件,就像一個(gè)shell腳本 只要有一個(gè)bash就能跑,而腳本不用安裝)
[root@web1 lnmp_soft]# cd /usr/local/tomcat/
[root@web1 tomcat]# ls
bin lib logs RELEASE-NOTES temp work
conf LICENSE NOTICE RUNNING.txt webapps
[root@web1 tomcat]# cd bin
[root@web1 bin]# ls
shutdown.sh(關(guān)閉服務(wù)腳本) startup.sh(啟動(dòng)) catalina.sh(關(guān)閉啟動(dòng))
[root@web1 bin]# ./catalina.sh start 啟服務(wù)
驗(yàn)證:
[root@web1 bin]# firefox http://192.168.2.100:8080 (tomcat端口號(hào)是8080,)
____________________________________________________________________________________________________________________________________________________________________________
實(shí)驗(yàn)1:
[root@web1 ROOT]# vim /usr/local/tomcat/webapps/ROOT/test.jpj
<html>
<body>
<center>
AAAAAAAAAAAAAAAAAAAAA
</center>
</body>
</html>
[root@web1 ROOT]# firefox http://192.168.2.100:8080/test.jpj
AAAAAAAAAAAAAAAAAAAA
[root@web1 ROOT]# firefox http://192.168.2.100:8080(默認(rèn)的話是出現(xiàn)下面index.html網(wǎng)頁(yè))
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
實(shí)驗(yàn)2:(多個(gè)web虛擬主機(jī))
[root@web1 conf]# cd /usr/local/tomcat/conf/
[root@web1 conf]# ls
Catalina context.xml tomcat-users.xml
catalina.policy logging.properties tomcat-users.xsd
catalina.properties server.xml web.xml
[root@web1 conf]# vim server.xml (主配置文件)
<Engine name="Catalina" defaultHost="localhost"> (若訪問(wèn)時(shí)輸入的不是域名是IP,那這里寫的域名主機(jī)就是那IP訪問(wèn)的)
........................................
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="www.a.com" appBase="a" (www.a.com)
unpackWARs="true" autoDeploy="true">
</Host>
<Host name="www.b.com" appBase="b" (www.b.com)
unpackWARs="true" autoDeploy="true">
</Host>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
#mkdir /usr/local/tomcat/{a,b}
#mkdir /usr/local/tomcat/{a,b}/ROOT
#echo "AaA" > /usr/local/tomcat/a/ROOT/tea.jpj
#echo "BbB" > /usr/local/tomcat/b/ROOT/teb.jpj
[root@proxe ~]# vim /etc/hosts
192.168.2.100 www.a.com www.b.com www.c.com
[root@proxe ~]# firefox http://www.b.com:8080/tea.jpj (有時(shí)需要把所有打開(kāi)的火狐瀏覽器關(guān)了,才有效果) 端口后面接文件不然默認(rèn)打開(kāi)的是index.html
[root@proxe ~]# firefox http://www.a.com:8080/teb.jpj
————————————————————————————————————————————————————————————————————————————————
實(shí)驗(yàn)3:(定義網(wǎng)頁(yè)存放路徑)
[root@web1 ~]# vim /usr/local/tomcat/conf/server.xml
<Host name="www.a.com" appBase="a"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="base" reloadable="true"/>
</Host>
# mkdir /usr/local/tomcat/a/base
# echo "base" >/usr/local/tomcat/a/base/index.html
# /usr/local/tomcat/bin/catalina.sh stop
# /usr/local/tomcat/bin/catalina.sh start
[root@proxe ~]# firefox http://www.a.com:8080
base
——————————————————————————————————————————————————————————--
實(shí)驗(yàn)4:(定義打開(kāi)時(shí)用文件/test,實(shí)際文件內(nèi)容保存位置另一地方)
[root@web1 bin]# vim /usr/local/tomcat/conf/server.xm
<Host name="www.a.com" appBase="a"
unpackWARs="true" autoDeploy="true">
<Context path="/test" docBase="/var/www/html/"/>
</Host>
[root@web1 bin]# echo "test" >/var/www/html/index.html
[root@web1 bin]# /usr/local/tomcat/bin/shutdown.sh
[root@web1 bin]# /usr/local/tomcat/bin/startup.sh
[root@proxe ~]# firefox www.a.com:8080/test
test
————————————————————————————————————————————————————————————————————
實(shí)驗(yàn)5:
[root@web1 bin]# mkdir /usr/local/tomcat/ssl
[root@web1 bin]# keytool -genkeypair -alias tomcat -keyalg RSA -keystore /usr/local/tomcat/ssl/keystore
[root@web1 bin]# vim /usr/local/tomcat/conf/server.xml
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
keystoreFile="/usr/local/tomcat/ssl/keystore" keystorePass="123456"
clientAuth="false" sslProtocol="TLS" />
<Host....
</Host>
[root@web1 bin]# /usr/local/tomcat/bin/catalina.sh stop
[root@web1 bin]# /usr/local/tomcat/bin/catalina.sh start
[root@proxe ~]# firefox https:www.a.com:8443
[root@proxe ~]# firefox https://192.168.2.100:8443
[root@proxe ~]# firefox https://www.b.com:8443
都是加密的 ------》》原因是tomcat做加密是對(duì)端口8043加密,不是對(duì)哪一個(gè)網(wǎng)站加密。這與ngins網(wǎng)站加密有區(qū)別?!?lt;Connector port="8443".....
<Host.... </Host> 』
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
配密鑰幫助:
[root@web1 bin]# keytool -h
非法選項(xiàng): -h
密鑰和證書(shū)管理工具
命令:
-certreq 生成證書(shū)請(qǐng)求
-changealias 更改條目的別名
-delete 刪除條目
-exportcert 導(dǎo)出證書(shū)
-genkeypair 生成密鑰對(duì)
-genseckey 生成密鑰
-gencert 根據(jù)證書(shū)請(qǐng)求生成證書(shū)
-importcert 導(dǎo)入證書(shū)或證書(shū)鏈
-importpass 導(dǎo)入口令
-importkeystore 從其他密鑰庫(kù)導(dǎo)入一個(gè)或所有條目
-keypasswd 更改條目的密鑰口令
-list 列出密鑰庫(kù)中的條目
-printcert 打印證書(shū)內(nèi)容
-printcertreq 打印證書(shū)請(qǐng)求的內(nèi)容
-printcrl 打印 CRL 文件的內(nèi)容
-storepasswd 更改密鑰庫(kù)的存儲(chǔ)口令
使用 "keytool -command_name -help" 獲取 command_name 的用法
[root@web1 bin]# keytool -genkeypair -h
非法選項(xiàng): -h
keytool -genkeypair [OPTION]...
生成密鑰對(duì)
選項(xiàng):
-alias <alias> 要處理的條目的別名
-keyalg <keyalg> 密鑰算法名稱
-keysize <keysize> 密鑰位大小
-sigalg <sigalg> 簽名算法名稱
-destalias <destalias> 目標(biāo)別名
-dname <dname> 唯一判別名
-startdate <startdate> 證書(shū)有效期開(kāi)始日期/時(shí)間
-ext <value> X.509 擴(kuò)展
-validity <valDays> 有效天數(shù)
-keypass <arg> 密鑰口令
-keystore <keystore> 密鑰庫(kù)名稱
-storepass <arg> 密鑰庫(kù)口令
-storetype <storetype> 密鑰庫(kù)類型
-providername <providername> 提供方名稱
-providerclass <providerclass> 提供方類名
-providerarg <arg> 提供方參數(shù)
-providerpath <pathlist> 提供方類路徑
-v 詳細(xì)輸出
-protected 通過(guò)受保護(hù)的機(jī)制的口令
使用 "keytool -help" 獲取所有可用命令
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
————————————————————————————————————————————————————————————————————————
給網(wǎng)站做日志:
[root@web1 logs]# vim /usr/local/tomcat/conf/server.xml
<Host name="www.a.com" appBase="a"
unpackWARs="true" autoDeploy="true">
<Context path="/test" docBase="/var/www/html/"/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="a.com" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
[root@web1 logs]# /usr/local/tomcat/bin/catalina.sh stop
[root@web1 logs]# /usr/local/tomcat/bin/catalina.sh start
[root@web1 logs]# ls
a.com.2017-02-20.txt (生成www.a.com網(wǎng)站日志) localhost.2017-02-20.log
catalina.2017-02-20.log localhost_access_log.2017-02-20.txt
catalina.out manager.2017-02-20.log
host-manager.2017-02-20.log
[root@proxe ~]# firefox http://www.a.com:8080
[root@web1 logs]# cat -n a.com.2017-02-20.txt |wc -l
4
[root@web1 logs]# tailf a.com.2017-02-20.txt
。。。。。。。。。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tomcat進(jìn)程優(yōu)化:
#vim tomcat/conf/server.xml
... ...
<Connector port=“8080“
protocol="HTTP/1.1“
maxThreads="1000“
//最大線程數(shù)
minSpareThreads="100“
//最少空閑進(jìn)程
maxSpareThreads="1000“
//最大空閑進(jìn)程
enableLookups="false“
//不對(duì)客戶端IP進(jìn)行反向DNS解析
URIEncoding="utf-8“
//編碼
acceptCount="1000“
//監(jiān)聽(tīng)端口隊(duì)列最大數(shù)
/>
調(diào)整Java虛擬機(jī)內(nèi)存:
#vim /usr/local/tomcat/bin/catalina.sh
249行:添加如下內(nèi)容
JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1024m -Xmx1024m"
|++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
新聞標(biāo)題:LTMJtomcat簡(jiǎn)單使用
分享URL:http://aaarwkj.com/article36/pccisg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)、建站公司、響應(yīng)式網(wǎng)站、網(wǎng)站收錄、、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)