Spring Download the domain / host configuration for access at www.website.com

I have a spring boot application. Usually I run my spring applications on PaaS instances, and setting the domain name from them is quite simple, however I run it on a virtual private server, and I can’t, for life, figure out how to run my spring, so it is available with the domain name .

I have already changed my DNS settings so that it points to my virtual private server, this VPS also launches some other static apache based websites, I'm sure my DNS settings are correct.

My spring boot application works with spring-boot-starter-tomcat , the application deploys fine, I can capture my .war file and deploy it using java -jar myApplication.jaron the server.

The application is also accessible remotely by writing my.server.ip:8080in a browser.

However, I searched a lot and cannot figure out how to configure spring boot so that it uses my domain name so that I can access the website in the standard way: www.mywebsite.comor better yet, but also add an alias, so both mywebsite.comand are acceptable www.mywebsite.com.

Can someone point me in the right direction? I know this can be done in Tomcat , but I don’t know how to configure it.

Since this is a spring boot application, I have no files .xml, my spring boot configuration is in a file application-prod.yml, and the only file .xmlI use is itself pom.xml.

Any help would be greatly appreciated.

+4
source share
2 answers

Technically, you can do this in Tomcat. However, to run the application with port 80 or 443, you will have to run it with root privileges. Therefore, I would recommend setting up both Apache HTTP or Nginx server as a reverse proxy (you can find many manuals for this topic).

+5
source

Due to the lack of answers, I decided to go with the approach suggested by dunni.

Here is how I did it using Nginx:

I went to a clean install of Windows nginx/conf/nginx.conf

, nginx.conf :

nginx.conf

worker_processes  1;
events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    include C:/path-to-nginx/nginx/conf/sites-enabled/*.conf;
}

sites-enabled nginx/conf/sites-enabled

mywebsite.conf sites-enabled:

mywebsite.conf

server {
    server_name  mywebsite.com;

    location / {
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://localhost:8080;
    }
}

, , Tomcat! , :


http://www.mkyong.com/nginx/nginx-apache-tomcat-configuration-example/

http://javadeveloper.asia/configuring-nginx-in-front-of-tomcat-or-other-java-application-server

http://nginx.org/en/docs/windows.html

nginx Windows:

.

+7

All Articles