Skip to main content

How to use an SSL certificate for both the API using SpringBoot and for the FontEnd using VueJS or ReactJS

In the previous post https://springboot-vuejs-reactjs.blogspot.com/2019/07/how-to-secure-springboot-with-ssl-and.html, we were doing the steps to get and install a certificate SSL for an apache tomcat embedded using SpringBoot, and we learned we can have as many SpringBoot applications secured with SSL as we want on the same server using the same  .p12 PKCS #12 file, so now we are going to be reviewing about how we can use the same certificate for apache tomcat and for an Nginx server at the same time.


we were working on the folder /root/SSL the last generated file was the apitester.p12 PKCS #12 file

to work with Nginx with need two files a .crt and .key file and as we started the process securing apache tomcat we do not have those files but we get them using a converter through this webpage:

https://decoder.link/converter

let's chose the option PKCS#12 TO PEM an let's download the apitester.p12 from the remote server and upload it to the online converter and give it the password with the one you started from the beginning, in this case, it was 123456 





download it and upload it to the remote server, you will get 3 files on it:

*bunlde.crt
*.key
*.crt




move those files to your preferred folder in this case /root/ssl_apitester.xyz


NOTE: " This is an important step because if we don't do it the site would be secured but that certificated is not going to be trusted on mobile devices ", we need to open the .crt file copy what it has got inside and paste it at this URL  https://decoder.link/result click on Decode and go to the option which says Bundle (Nginx) let's download it, unzip it, and let's upload it to the remote server to the folder 
/root/ssl_apitester.xyz, in my case it got downloaded by the name nginx_bundle_91fe9d0bff9c.crt, change it according to the file name you get.




now, let's open the nginx.conf file in my case it is at /etc/nginx/nginx.conf
as I have an Nginx higher version than 9.x I can activate the protocol http2




server {

listen 443 http2;
listen [::]:443 ssl http2;


ssl on;

ssl_certificate /root/ssl_apitester.xyz/nginx_bundle_91fe9d0bff9c.crt;

ssl_certificate_key /root/ssl_apitester.xyz/ddccb60f754a15650969adab38eadde7.key;

server_name  apitester.xyz;
access_log /var/log/nginx/nginx.vhost.access.log;
error_log /var/log/nginx/nginx.vhost.error.log;

root  /var/www/apitester.xyz;

location / {

root /var/www/apitester.xyz;
try_files $uri /index.html;

}

ssl_protocols TLSv1.2;

}


and that's it, let's run service nginx restart and the domain name https://apitester.xyz on the 443 port are working perfect with the 8443 too at the same time.

to test it go to this URL https://decoder.link/

after you set your domain name and port 443 everything should be OK


How to redirect HTTP to HTTPS in Nginx

server {

    #what this command lines do it is to force all request done using HTTP to send them to HTTPS,
    #when it detects that apitester.xyz is being called through the 80 port,
    #it makes a 301 that inmediately makes a redirect to the 443 HTTPS
    listen 80;

    server_name apitester.xyz;
    return 301 https://apitester.xyz$request_uri;
}





Comments

  1. I have just gone through your blog......your information is so valuable. Im logu from Chennai Corporate Email Solutions

    ReplyDelete
  2. Great Content. It will useful for knowledge seekers. Keep sharing your knowledge through this kind of article.
    React JS Training Institute in Chennai
    React JS Training Center in Chennai

    ReplyDelete
  3. Do you know which things should be considered when it comes to hiring Reactjs Developers? If you don't know you must know how to choose a ReactJS development company from the top-notch react service providers.
    You can see a bunch of development service providers out there and individually promises that they are reputable ReactJS Development company in all forms. But I would recommend you choose the right one that helps your business grow.

    ReplyDelete
  4. How to use an SSL certificate for both the API using SpringBoot and for the FontEnd using VueJS or ReactJS

    Very interesting post...! It will help the developers to use SSL certificate..

    Well, we are here to share our blog - Top 7 Reasons to Choose ReactJS for Business App Development

    reactjs development services

    ReplyDelete

Post a Comment

Popular posts from this blog

How to secure SpringBoot with SSL and Tomcat or Undertow

when we are going to take our applications to production mode, we must have an SSL certificate for the FrontEnd and   BackEnd too, in this case, our backend is a  SpringBoot which is using a tomcat embedded server. Terminology TLS vs SSL TLS is the successor to SSL. It is a protocol that ensures privacy between communicating applications. Unless otherwise stated, in this document consider TLS and SSL as interchangable. Certificate (cert) The public half of a public/private key pair with some additional metadata about who issued it etc. It may be freely given to anyone. Private Key A private key can verify that its corresponding certificate/public key was used to encrypt data. It is never given out publicly. Certificate Authority (CA) A company that issues digital certificates. For SSL/TLS certificates, there are a small number of providers (e.g. Symantec/Versign/Thawte, Comodo, GoDaddy, LetsEncrypt) whose certificates are included by most browsers and Op...

How to deploy a VueJS App using Nginx on Ubuntu

There are thousands of blogs and websites out there explaining how to do a hello world and how to start with VueJS, but in this little post, I’m just going to be explaining how to do deploy a VueJs app after you have run the command through the CLI npm run build . So when you run the command npm run build a dist folder is created and that folder’s got the essential .js files to run our app, when we want to run our app on an Nginx server by default the vue-router is not going to work well so that Nginx does not come ready to work by default with a VueJs app This is basically for a Linux Ubuntu distribution if you’ve got any other Linux distribution just pay attention where is going to be set the www/html folder and the Nginx settings so that this is useful for any Linux distribution  Install and configure nginx sudo apt install nginx Double check to make sure the nginx service is running with command service nginx status, then open your browser and enter ...

Printing using SpringBoot - cups4j

One of the easiest ways to print something from Java , in this case, using a SpringBoot Java Api Rest is with CUPS . Let's assume you've set up your CUPS server up and running, add to your pom.xml file this dependency      < dependency >      < groupId > org.cups4j </ groupId >      < artifactId > cups4j </ artifactId >      < version > 0.7.6 </ version > </ dependency > now at this imports to import  java.io.FileInputStream; import  java.io.FileNotFoundException; import  java.net.URL; import  java.util.HashMap; import  java.util.List; import  org.cups4j.CupsClient; import  org.cups4j.CupsPrinter; import  org.cups4j.PrintJob; import  org.cups4j.PrintJobAttributes; import  org.cups4j.PrintRequestResult; import  org.cups4j.WhichJobsEnum; add this method to prin...