Hello everyone, I am xiao CAI, a desire to do CAI Not CAI xiao CAI in the Internet industry. Soft but just, soft praise, white piao just!Ghost ~ remember to give me a three – even oh!

This article describes how to enable HTTPS

Refer to it if necessary

If it is helpful, do not forget the Sunday

First, preparation

  • One server (you can buy ali Cloud lightweight application server, which is relatively cheap)
  • SSL certificate (can register ali Cloud free certificate, poor security)
  • One domain name (can be purchased on Wan.com and should be put on record)
  • Locally packaged projects (bloggers are developed using Springboot, so packaged jar packages instead of war packages)
  • ftpThe client

Set up the environment (database, JDK, etc.) on the server first, because the demonstration project is made bySpringBootBuild, there is a built-in running container, so do not use Tomcat.

1) SSL certificate

You can apply for the free version on Ali CloudSSLCertificates are also accessibleFreeSSLSite to register for a free certificate

2) The domain name needs to be resolved after the registration is successful

Go to Ali cloud console, enter domain name management

3) After the analysis, click on the certificate application and fill in the relevant information

Once the application is approved, it can be downloaded

4) injectionServletWebServerFactory

Inject the ServletWebServerFactory into the boot class in our SpringBoot project:

@Bean

public ServletWebServerFactory servletContainer(a){

    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();

    tomcat.addAdditionalTomcatConnectors(createHTTPConnector());

    return tomcat;

}



private Connector createHTTPConnector(a) {

    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");

    // Enable both HTTP (8080) and HTTPS (8866) ports

    connector.setScheme("http");

    connector.setSecure(false);

    connector.setPort(8080);

    connector.setRedirectPort(8866);

    return connector;

}

Copy the code

Then, inapplication.propertiesAdded to the configuration file Notice here isserver.ssl.key-store-passwordRather thanserver.ssl.key-password

5) Package projects

Put your packaged project and downloaded certificate in the usr/develop/project folder of your choice.

In order to facilitate myself to build a few scripts to run.

  • vim start.sh

    Create the startup script as follows:

Nohup java-jar is the name of its own project. Jar &

Copy the code
  • vim stop.sh

    Create a stop script as follows:

PID = $(ps - ef | grep own project name. The jar | grep -v grep | awk '{print $2})

if [ -z "$PID" ]

then

    echo Application is already stopped

else

    echo kill $PID

    kill -9 $PID

fi

Copy the code
  • vim run.sh

    Create the run script as follows

echo stop application

source stop.sh

echo start application

source start.sh

Copy the code

Enter./run.sh on the terminal. If no permission is displayed, enter

chmod u+x *.sh

Copy the code

Then type./run.sh to start our application, and we can access our project in the browser with https:// domain name: port number

They’re all bad guys

Today you work harder, tomorrow you will be able to say less words!

I am xiao CAI, a man who studies with you. 💋