Tomcat 详解(安装Tomcat、启动和配置,发布一个web网站)

接下来开始 Tomcat DE 详细介绍。

一. 安装Tomcat

官网下载地址:Tomcat 下载地址(Tomcat 10.0)
在这里插入图片描述
下载完毕以后,解压

二. Tomcat 启动和配置

2.1 目录文件

  • bin 文件夹 — 启动、关闭Tomcat
  • conf 文件夹 – 配置
  • lib 文件夹 – 依赖的 jar 包
  • logs 文件夹 – 日志
  • webapps – 存放网站

2.2 启动 Tomcat、测试

  • 打开 bin 文件夹;双击 startup(打开以后,命令窗口不要关闭

  • 打开浏览器,输入 localhost:8080

当出现上述界面,说明启动成功!

2.3 关闭 Tomcat

三. 配置

  • 打开 conf 文件件,选择 server.xml 文件(配置文件)
    在这里插入图片描述

  • tomcat的默认端口号为:8080

  • mysql:3306

  • http:80

  • https:443

    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
  • 配置主机的名称
  • 默认的主机名为:localhost->127.0.0.1
  • 默认网站应用存放的位置为:webapps
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
  • 可在 C:\Windows\System32\drivers\etc 文件夹下的 host 文件修改 主机名
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost

四. 发布一个 web 网站

将自己写的网站,放到服务器 (Tomcat) 中指定的 web 应用的文件夹(webapps)下,就可以访问了

  • 打开 webapps 文件夹,下面均可以直接运行
- 输入 **localhost:8080/examples**

五.常见面试题

问:请你谈谈网站是如何进行访问的!

  1. 输入一个域名;回车

  2. 检查本机的 C:\Windows\System32\drivers\etc\hosts配置文件下有没有这个域名映射;

    • 有:直接返回对应的ip地址,这个地址中,有我们需要访问的web程序,可以直接访问

      127.0.0.1      localhost
      
    • 没有:去DNS服务器找,找到的话就返回,找不到就返回找不到;

  3. 可以配置一下环境变量(可选性)

猜你喜欢

转载自blog.csdn.net/Kc635908933/article/details/114383175