Home > OS >  Configuring VirtualHost in Spring Boot application embedded Tomcat server in Windows
Configuring VirtualHost in Spring Boot application embedded Tomcat server in Windows

Time:10-06

I have a private Windows server running a Spring Boot jar file and I can access it via the IP address. I have a few websites available which I am able to access via the IP address and filters. (Note that this is running on port 54654 as I have other WEB APIs as well). I have a new domain registered online and I would like to access the server by the domain name which would redirect to my server address.

But the issue is, the browser shows the IP address instead of the domain name. I tried forward with masking but it is not working as I expected (it puts the site inside an iFrame and I cannot access browser properties etc). I want to access my site like www.abc.com and it should not change to <host-ip-address>:<port>. I understand the issue is from server side and do not know how to make it remain in the domain name. I tried a new entry with hosts.txt file but it does not seem to work.

I have searched for solution online for hours and could not find a specific solution for Spring Boot and changing VirtualHost settings in tomcat is not clear to me in this case. Is there any settings for this in application.properties file?

CodePudding user response:

So this is the summary of things I learnt from this requirement. Thank you @PiotrP.Karwasz for your extended support.

  1. You can run your server in any port but the domain name provider can only point to the default port (80)

  2. If you change your forwarding setting AFTER you have edited your A record, your domain will be moved to Parked state (Parked is when your domain is shown as "taken" to others who visit it and it will not point to your A record's IP address). In such case, you have to modify your A record again.

  3. You can use nginx to configure reroute from http port (80) to any port your server runs in. My nginx configuration:

    server {
    listen 80;
    server_name <my-site>.com;
    
        location / {
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_set_header   Host $http_host;
        proxy_pass         "http://127.0.0.1:<my-port>";
        }
    }
    
  4. Domain name changes will take time to reflect in DNS (24-48 hours) and you can check it by clearing cache or by incognito window (private browsing).

  • Related