How to Configure SSL Certificate on Localhost React Project Using OpenSSL and Make it HTTPS Secure

 

In this guide, we will set up an SSL certificate for a localhost React project using OpenSSL, making it HTTPS secure.

Step 1: Install OpenSSL

 

First, you need to have OpenSSL installed on your machine. You can download it from OpenSSL Official Site for Windows or install it via the package manager:

 

  • Windows: Download and install OpenSSL from the official website.
  • Mac: Run the following command:

 

 

Linux: Run the following command:

 

 

Step 2: Generate a Self-Signed SSL Certificate

 

Navigate to a directory where you want to store your certificates and run the following OpenSSL commands:

 

 

You will be prompted to enter information such as country, state, city, organization, etc. You can leave them blank or enter dummy data.

Step 3: Trust the Certificate (Mac and Windows)

 

To prevent browser warnings, you need to trust the self-signed certificate.

 

  • Mac: Open Keychain Access, drag and drop localhost.crt into the System keychain, then double-click it and set Always Trust.

 

  • Windows: Open certmgr, import the localhost.crt into Trusted Root Certification Authorities.

 

 

Step 4: Configure React Development Server

 

Modify your package.json to include HTTPS settings. Update the scripts section:

 

 

For Create React App (CRA), the react-scripts start command will now use HTTPS.

Step 5: Run the React Project with HTTPS

 

Start the development server with:

 

 

Your React app will now run on https://localhost:3000 with an SSL certificate.

 

 

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *