Search code examples
spring-bootnginxsubdomainwildcard-subdomainembedded-tomcat-8

How can we configure subdomain in spring-boot?


How can we configure subdomain in spring-boot? We use the embedded Tomcat server. Any idea of how to go ahead with it. I was told that we cannot use ngnix in spring-boot embedded tomcat.


Solution

  • Subdomain is on the DNS level and has nothing to do with Spring Boot.

    You have to have a web server in front of the Spring Boot app like nginx or Apache that will act as a reverse proxy.

    With nginx this could look like this:

    server {
      listen 80 default_server;
      server_name subdomain.domain.com;
      location / {
          proxy_pass http://localhost:8080;
          proxy_set_header Host      $host;
          proxy_set_header X-Real-IP $remote_addr;
      }
    }
    

    Edit

    If you only want to pass to one page:

    proxy_pass http://localhost:8080/the_one_and_only_page.html;