首页 > 解决方案 > lochalhost:8080 不显示 Centos 8 Tomcat SpringBoot 服务器内容

问题描述

作为使用 Centos 8 Vagrant 虚拟机本地部署 GitHub 项目的一部分,我在 GitBash 中运行“vagrant up”后得到以下结果:

虚拟机日志:

  default:
default:               |\      _,,,--,,_
default:              /,`.-'`'   ._  \-;;,_
default:   _______ __|,4-  ) )_   .;.(__`'-'__     ___ __    _ ___ _______
default:  |       | '---''(_/._)-'(_\_)   |   |   |   |  |  | |   |       |
default:  |    _  |    ___|_     _|       |   |   |   |   |_| |   |       | __ _ _
default:  |   |_| |   |___  |   | |       |   |   |   |       |   |       | \ \ \ \
default:  |    ___|    ___| |   | |      _|   |___|   |  _    |   |      _|  \ \ \ \
default:  |   |   |   |___  |   | |     |_|       |   | | |   |   |     |_    ) ) ) )
default:  |___|   |_______| |___| |_______|_______|___|_|  |__|___|_______|  / / / /
default:  ==================================================================/_/_/_/
default:
default: :: Built with Spring Boot :: 2.4.5
default:
default: 2021-08-09 00:25:52.606  INFO 27111 --- [           main] o.s.s.petclinic.PetClinicApplication     : Starting PetClinicApplication v2.4.5 using Java 1.8.0_302 on localhost.localdomain with PID 27111 (/home/vagrant/spring-petclinic/target/spring-petclinic-2.4.5.jar started by vagrant in /home/vagrant/spring-petclinic)
default: 2021-08-09 00:25:52.624  INFO 27111 --- [           main] o.s.s.petclinic.PetClinicApplication     : No active profile set, falling back to default profiles: default
default: 2021-08-09 00:25:54.610  INFO 27111 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
default: 2021-08-09 00:25:54.696  INFO 27111 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 76 ms. Found 4 JPA repository interfaces.
default: 2021-08-09 00:25:55.664  INFO 27111 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
default: 2021-08-09 00:25:55.685  INFO 27111 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
default: 2021-08-09 00:25:55.685  INFO 27111 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.45]
default: 2021-08-09 00:25:55.885  INFO 27111 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
default: 2021-08-09 00:25:55.886  INFO 27111 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3152 ms
default: 2021-08-09 00:25:56.535  INFO 27111 --- [           main] org.ehcache.core.EhcacheManager          : Cache 'vets' created in EhcacheManager.
default: 2021-08-09 00:25:56.552  INFO 27111 --- [           main] org.ehcache.jsr107.Eh107CacheManager     : Registering Ehcache MBean javax.cache:type=CacheStatistics,CacheManager=urn.X-ehcache.jsr107-default-config,Cache=vets
default: 2021-08-09 00:25:56.563  INFO 27111 --- [           main] org.ehcache.jsr107.Eh107CacheManager     : Registering Ehcache MBean javax.cache:type=CacheStatistics,CacheManager=urn.X-ehcache.jsr107-default-config,Cache=vets
default: 2021-08-09 00:25:56.672  INFO 27111 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
default: 2021-08-09 00:25:56.950  INFO 27111 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
default: 2021-08-09 00:25:57.220  INFO 27111 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
default: 2021-08-09 00:25:57.324  INFO 27111 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.30.Final
default: 2021-08-09 00:25:57.493  INFO 27111 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
default: 2021-08-09 00:25:57.655  INFO 27111 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
default: 2021-08-09 00:25:58.813  INFO 27111 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
default: 2021-08-09 00:25:58.826  INFO 27111 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
default: 2021-08-09 00:25:59.968  INFO 27111 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
default: 2021-08-09 00:26:01.442  INFO 27111 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 13 endpoint(s) beneath base path '/actuator'
default: 2021-08-09 00:26:01.533  INFO 27111 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
default: 2021-08-09 00:26:01.568  INFO 27111 --- [           main] o.s.s.petclinic.PetClinicApplication     : Started PetClinicApplication in 9.688 seconds (JVM running for 10.503)

流浪文件:

    Vagrant.configure("2") do |config|

  config.vm.box = "centos/8"

  config.vm.synced_folder ".", "/vagrant", type: "rsync"

  config.vm.network "forwarded_port", guest: 8443, host: 8080

  config.vm.provider "virtualbox" do |vb|
    vb.memory = "4096"
    vb.cpus = "2"
  end

  config.vm.provision "shell", privileged: false, inline: <<-SHELL

    echo "whoami..."
    whoami

    echo "pwd..."
    pwd

    # echo "upgrading..."
    # sudo yum upgrade -y

    echo "installing unzip..."
    sudo yum install unzip -y

    echo "installing git..."
    sudo yum install git -y

    echo "installing mysql..."

    sudo dnf install mysql-server -y

    sudo systemctl enable mysqld

    sudo systemctl start mysqld.service

    sudo systemctl status mysqld



    echo "installing java..."

    sudo yum install java-11-openjdk-devel -y


    sudo yum install maven -y


    git clone https://github.com/spring-projects/spring-petclinic.git
    sleep 30

    cd spring-petclinic

    echo "running project jar"
    ./mvnw package
    java -jar target/*.jar




  SHELL

end

如图所示,Tomcat 服务器似乎在正确的端口上运行,没有明显错误。但是,在我的 Chrome 搜索栏中输入 http://localhost:8080/(正确的输入地址)后,我会收到一个错误屏幕,其中包含以下消息:

此页面不工作

localhost 没有发送任何数据。

ERR_EMPTY_RESPONSE

该站点使用 H2 内存数据库,通常可以通过导航到 http://localhost:8080/h2-console 来访问该数据库,但这不起作用并产生相同的错误。

之后我尝试在端口 8080 上运行另一个应用程序,并且能够确认端口 8080 确实被我的初始 webapp 使用,因为第二个应用程序没有运行并产生错误。

假设源 GitHub 项目没有任何问题(我可以自信地声称没有),我做错了什么导致这个问题,如何解决?

标签: spring-boottomcatvagrantvagrantfilecentos8

解决方案


在它显示的日志中,Tomcat started on port(s): 8080 (http) with context path但是您将主机上的 8080 连接到来宾上的端口 8443。

尝试将客户机上的目标端口也更改为 8080。查看vagrant 转发端口

 config.vm.network "forwarded_port", guest: 8080, host: 8080

在 vagrant shell 中运行服务器的整个概念似乎很奇怪。我认为这只是一些快速且非常肮脏的测试。最好看看使用诸如 ansible 之类的东西来配置您的客人。


推荐阅读