Tomcat基本Web配置


 
第一步下载tomcat到服务器,这里以本地开发为例,window环境下,Linux下同理。


第二部打开/conf/server.xml文件

 1、先找到Connector配置链接参数

[html] 
<Connector port="80" protocol="HTTP/1.1"  
           connectionTimeout="20000"  
  URIEncoding="UTF-8" 
  maxThreads="300" enableLookups="false" 
  emptySessionPath="true" 
           redirectPort="8443" /> 
主要有两个参数解释一下
port: Tomcat默认是8080端口,改成80端口,也就是默认的http端口,这样就可以监听http请求了

URIEncoding:URL地址使用get方法可以兼容中文,也可以改成gbk,不改的话就是乱码了,这样就不至于乱码

例如:window.location.href = "http://www.abc.com/?name="+encodeURIComponent("大大网");

其他参数意义参照那篇文章,很详细

2、找到host节点 配置host

[html]
<Host name="www.abc.com"  appBase="webapps" 
            unpackWARs="true" autoDeploy="true" 
            xmlValidation="false" xmlNamespaceAware="false"> 
        <Context docBase="war-taglib" path=""  reloadable="true" /> 
</Host> 
修改几个参数:
name: 原来是localhost 修改为www.abc.com 这就是你的域名

里面再加一个context节点 docBase就是你的war名称


如果你的配置文件是抽出去放在另外目录下,还需要修改catalina.properties

添加:

CONFIG_DIR_PATH=F:\\config\\config (注意Linux下的分隔符)
这样你就可以在项目中使用CONFIG_DIR_PATH变量了

例如Spring里面可以这样

[html] 
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
        <property name="order" value="2" /> 
        <property name="ignoreUnresolvablePlaceholders" value="true" /> 
        <property name="locations"> 
            <list> 
                <value>file:${CONFIG_DIR_PATH}/tag.properties</value> 
                <value>file:${CONFIG_DIR_PATH}/../system-config/tag.properties</value> 
            </list> 
        </property> 
    </bean> 

至此,Tomcat配置就算完成了。

第三步 绑定host 就不说了。


第四步 启动 访问 http://www.abc.com


以上配置是最最基本最最简单的,不适用与生产环境哦~


有空把nginx也整合进来

 

相关内容

    暂无相关文章