1. 程式人生 > >【JBoss】4. 配置JBoss Web伺服器

【JBoss】4. 配置JBoss Web伺服器

JBoss Web伺服器建立在Apache Tomcat 6.0的基礎上,結合了Tomcat的多功能性和Apache HTTP伺服器的速度。

配置URL路徑

針對客戶端傳來的一個URL(協議 :// 域名 : 埠號 / 上下文路徑 / 資源),JBoss Web伺服器如何確定呼叫哪個應用程式?

1、server.xml配置聯結器:協議、埠號

配置檔案:

\server\production\deploy\jbossweb.sar\server.xml

\server\production\deployers\jbossweb.deployer\server.xml

JBoss支援Http、Https協議;還支援AJP協議,允許本地Web伺服器在二進位制格式中傳送請求,速度較快。


所以在server.xml中可以定義HTTP聯結器、HTTPS聯結器、AJP聯結器:

<Server>

   <Service name="jboss.web">

      <!-- A HTTP/1.1 Connector on port 8080 -->
<!--redirectPort=443, 即轉交給第三個Connector(https)處理-->
<!--注意,需要同時在web.xml中配置transport-guarantee才可對指定URL生效-->
<Connector protocol="HTTP/1.1" port="80" address="${jboss.bind.address}" 
           connectionTimeout="20000" redirectPort="443" URIEncoding="UTF-8" 
           compression="on" compressableMimeType="text/html,text/xml,text/css,text/javascript, 
             application/x-javascript,application/javascript,application/json"/>
<Connector protocol="HTTP/1.1" port="8080" address="${jboss.bind.address}" 
           connectionTimeout="20000" redirectPort="443" URIEncoding="UTF-8" 
           compression="on" compressableMimeType="text/html,text/xml,text/css,text/javascript, 
             application/x-javascript,application/javascript,application/json"/>
<!--port=443-->
<Connector protocol="HTTP/1.1" SSLEnabled="true" port="443" address="${jboss.bind.address}" 
           scheme="https" secure="true" clientAuth="false" keystoreFile="${javax.net.ssl.keyStore}" 
           truststoreFile="${javax.net.ssl.trustStore}" keystorePass="${javax.net.ssl.keyStorePassword}" 
           truststorePass="${javax.net.ssl.trustStorePassword}" sslProtocol="TLS" URIEncoding="UTF-8" 
           compression="on" compressableMimeType="text/html,text/xml,text/css,text/javascript, 
             application/x-javascript,application/javascript,application/json"/>
<Connector protocol="HTTP/1.1" SSLEnabled="true" port="8443" address="${jboss.bind.address}" 
           scheme="https" secure="true" clientAuth="false" keystoreFile="${javax.net.ssl.keyStore}" 
           truststoreFile="${javax.net.ssl.trustStore}" keystorePass="${javax.net.ssl.keyStorePassword}" 
           truststorePass="${javax.net.ssl.trustStorePassword}" sslProtocol="TLS" URIEncoding="UTF-8" 
           compression="on" compressableMimeType="text/html,text/xml,text/css,text/javascript, 
             application/x-javascript,application/javascript,application/json"/>

      <!-- Add this option to the connector to avoid problems with 
          .NET clients that don't implement HTTP/1.1 correctly 
         restrictedUserAgents="^.*MS Web Services Client Protocol 1.1.4322.*$"
      -->

      <!-- A AJP 1.3 Connector on port 8009 -->
      <Connector protocol="AJP/1.3" port="8009" address="${jboss.bind.address}" redirectPort="8443"/>


<Engine name="jboss.web" defaultHost="localhost">

         <!-- The JAAS based authentication and authorization realm implementation
         that is compatible with the jboss 3.2.x realm implementation.
         - certificatePrincipal : the class name of the
         org.jboss.security.auth.certs.CertificatePrincipal impl
         used for mapping X509[] cert chains to a Princpal.
         - allRolesMode : how to handle an auth-constraint with a role-name=*,
         one of strict, authOnly, strictAuthOnly
           + strict = Use the strict servlet spec interpretation which requires
           that the user have one of the web-app/security-role/role-name
           + authOnly = Allow any authenticated user
           + strictAuthOnly = Allow any authenticated user only if there are no
           web-app/security-roles
         -->
         <Realm className="org.jboss.web.tomcat.security.JBossWebRealm" certificatePrincipal="org.jboss.security.auth.certs.SubjectDNMapping" allRolesMode="authOnly"/>
         

         <Host name="localhost">
             <Valve className="org.jboss.web.rewrite.RewriteValve"/>             
             <Valve className="org.jboss.web.tomcat.service.sso.ClusteredSingleSignOn" requireReauthentication="true"/>                
         </Host>
      </Engine>

  


2、jboss-web.xml配置上下文路徑

預設情況下,JBoss使用WAR程式包的名稱作為上下文路徑,

配置檔案:

\WEB-INF\jboss-web.xml

該配置檔案的<context-root>屬性值會覆蓋掉預設配置:

<jboss-web>
      <context-root>/</context-root>
</jboss-web>

注意,上例中配置為“根上下文路徑”,那麼同時要需要刪除預設的根WEB應用程式(ROOT.war)

對於企業應用程式,則在application.xml中配置:

<application>
  <module>
      <web>
          <web-uri>com.alpha.web.war</web-uri>
          <context-root>/ris</context-root>
      </web>
  </module>

3、web.xml配置資源

<web-app>
	<listener>
		<listener-class>com.alpha.webstart.WebstartContextListener</listener-class>
	</listener>

        <servlet>
		<servlet-name>JnlpDownloadServlet</servlet-name>
		<servlet-class>jnlp.sample.servlet.JnlpDownloadServlet</servlet-class>
	</servlet>
	<servlet>
		<servlet-name>CertificateServlet</servlet-name>
		<servlet-class>com.alpha.webstart.CertificateServlet</servlet-class>
	</servlet>

        <servlet-mapping>
		<servlet-name>JnlpDownloadServlet</servlet-name>
		<url-pattern>*.jar</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>JnlpDownloadServlet</servlet-name>
		<url-pattern>*.jnlp</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>CertificateServlet</servlet-name>
		<url-pattern>/certificate</url-pattern>
	</servlet-mapping>

        <filter>
		<filter-name>CompressingFilter</filter-name>
		<filter-class>com.planetj.servlet.filter.compression.CompressingFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>CompressingFilter</filter-name>
		<url-pattern>*.jnlp</url-pattern>
	</filter-mapping>
</web-app>


配置JBoss Web伺服器

1、配置虛擬主機

所謂虛擬主機,是分割Web容器以向某些域 提供指定應用程式的機制。

同一個Web伺服器可以擁有不同的域,每個域中包含不同的應用程式;即將不同的應用程式繫結到不同的虛擬主機上,如圖:


步驟一,server.xml在聯結器上啟用虛擬主機

配置檔案:

\server\production\deploy\jbossweb.sar\server.xml

\server\production\deployers\jbossweb.deployer\server.xml

將聯結器的useIPVHosts特性設為true

步驟二,server.xml定義虛擬主機

配置檔案:

\server\production\deploy\jbossweb.sar\server.xml

\server\production\deployers\jbossweb.deployer\server.xml

<Connector protocol="AJP/1.3" port="8009" address="${jboss.bind.address}" redirectPort="8443"/>

<Engine name="jboss.web" defaultHost="localhost">
     <Host name="localhost" autoDeploy="false" deployOnStartup="false" deployXML="false">
         <!--閥門、攔截器;當請求每次進入伺服器時執行特定操作,例如記錄客戶端IP、查詢是否在黑名單中-->
         <Valve className="org.jboss.web.tomcat.service.sso.ClusteredSingleSignOn" requireReauthentication="true"/>
     </Host>
     <Host ...>


預設情況下,Host.name=localhost,表示虛擬主機能夠處理進入伺服器的每一個請求。

步驟三,jboss-web.xml將應用程式繫結到虛擬主機中

配置檔案:

WEB-INF\jboss-web.xml

<jboss-web>
    <virtual-host>www.site1.com<virtual-host>
</jboss-web>


2、全域性應用程式配置

如果每個應用程式都有一些相同配置,則可以將這些配置提取到“全域性配置檔案”中

WEB-INF/web.xml      ---- deployers/jbossweb.deployer/web.xml

WEB-INF/context.xml ---- deploy/jbossweb.sar/context.xml

WEB-INF/jboss-web.xml  ---- 無

web.xml被稱為標準部署描述符;context.xml和jboss-web.xml被稱為專用部署描述符。

各配置檔案的作用總結: