1. Connect to Your EC2 Server
Use SSH to connect to your EC2 instance:2. Generate SSL Key and CSR
Create the private key and certificate signing request (CSR):3. Obtain SSL Certificates
- Go to your SSL provider (e.g., GoDaddy, Namecheap, or any hosting site that sells SSL certificates).
- Copy the contents of
linqra.csrand paste it into the provider’s CSR box. - Submit and wait for approval.
- Download the resulting ZIP file (Server type: Other), e.g.
linqra.com.zip.
f8d48b14580110e.crtf8d48b14580110e.pem(identical to the .crt)gd_bundle-g2.crt
4. Upload Certificates to the Server
Use FileZilla, IntelliJ, or another SFTP tool to upload the two.crt files to /tmp/ on your EC2 server.
Then move them to the target directory:
Note: The.pemand.crtfiles from your provider are often identical.
5. Generate the Certificate Chain
Switch to root and concatenate the certificate and bundle to create the chained certificate:You now have all the necessary SSL files (
linqra.key, linqrachained2025.crt) to configure your web server for HTTPS on linqra.com.
6. Set Up AWS EC2 Folders and Prepare for Deployment
Create the necessary directories for your application and logs:7. Manage Nginx
You may need these commands to manage the Nginx service:8. Configure Nginx for SSL and React Frontend
Edit the default Nginx site configuration:9. Enable the Nginx Site
Symlink thesites-available file to the sites-enabled folder:
10. Set Permissions for Deployment
Navigate to your deployment directory and set the correct permissions:Note:
- Always edit the
sites-availablefile for Nginx configuration. - Adjust the paths and domain names as needed for your environment.
11. Configure GitHub Actions Repository Secrets
To enable automated deployment and secure access, add the following secrets to your GitHub repository:1. SSH Key for EC2
Generate or use your existing SSH private key.Example (do not use this key, just for illustration):
2. EC2 Host and Deployment Info
Add the following repository secrets:3. AWS Credentials
4. Web Application Secrets
Copy these from your web environment files and add as repository secrets:How to add a secret:
- Go to your GitHub repository.
- Click on Settings > Secrets and variables > Actions.
- Click New repository secret.
- Enter the name and value, then click Add secret.
Tip:
Never commit your private keys or secrets to the repository. Always use GitHub Actions secrets for sensitive data.

ci.yml workflow will automatically deploy all necessary files to your EC2 server whenever new code is merged into the master branch. This ensures a secure and automated deployment process.
We’ll cover the Dockerization steps for your application in the next section.
12. Final GitHub Actions CI/CD Pipeline (ci.yml)
Below is the complete ci.yml workflow file used for automated deployment.Once code is merged into the
master branch, this pipeline will automatically build and deploy your application to the EC2 server—no additional manual steps are required.
2. Initialize the Replica Set
At themongosh prompt, run:
3. Check Replica Set Status
PRIMARY and SECONDARY members.
Note:
- This setup is only required the first time you deploy your stack.
- For more information, see the MongoDB Replica Set documentation.
14. First Initial Data
After initializing the MongoDB replica set, you need to create the initial user and data for your application.1. Exit the MongoDB Shell
If you are still inside themongosh shell, type:
2. Run the Initial Setup API Call
Usecurl to create the first user and initialize the database:
3. Verify Data in MongoDB
Connect to MongoDB and list the databases to confirm theLinqra database was created:
Linqra database listed.
15. Keycloak Configuration for EC2
Access Keycloak Admin Console
Access the Keycloak Admin Console at:1. Create New Realm
- Log in to the Keycloak Admin Console
- Click on the dropdown in the top-left corner (default shows “master”)
- Click “Create Realm”
- Configure the realm:
- Realm name:
Linqra - Display name:
Linqra - Frontend URL:
https://linqra.com/keycloak
- Realm name:
- Ensure “Enabled” is switched ON
- Click “Create”
2. Create New Client
General Settings
- Navigate to “Clients” in the left sidebar
- Click “Create client”
- Configure the general settings:
- Client ID:
linqra-gateway-client - Name:
Linqra Gateway Client - Description:
Linqra Gateway Client - Always display in UI:
ON - Click “Next”
- Client ID:
Access Settings
Configure the client’s access settings:- Root URL:
https://linqra.com - Home URL:
https://linqra.com - Valid redirect URIs:
https://linqra.com/callback - Valid post logout redirect URIs:
https://linqra.com - Web origins:
https://linqra.com - Admin URL:
https://linqra.com
Capability Config
Set up the authentication capabilities:- Client authentication:
ON - Authorization:
OFF - Authentication flow:
- Standard flow:
Enabled - Service accounts roles:
Enabled - All other flows:
Disabled
- Standard flow:
3. Create Client Role
- Navigate to the “Roles” tab in your client settings
- Click “Create role”
- Configure the role:
- Role name:
gateway_admin - Description:
Gateway admin role for the client id: linqra-gateway-client
- Role name:
- Click “Save”
4. Create Realm Role
- Navigate to “Realm roles” in the left sidebar
- Click “Create role”
- Configure the role:
- Role name:
gateway_admin_realm - Description:
Role to identify the belongings of the Linqra realm
- Role name:
- Click “Save”
5. Assign Service Account Roles
- Navigate to your client’s “Service accounts roles” tab
- You’ll see the service account username:
service-account-linqra-gateway-client - Assign both roles:
- Client role:
gateway_admin - Realm role:
gateway_admin_realm
- Client role:
6. Create Client Scopes
a. Gateway Read Scope
- Navigate to “Client scopes” in the left sidebar
- Click “Create client scope”
- Configure the scope:
- Name:
gateway.read - Description:
To read the gateway end points - Type:
Default - Display on consent screen:
ON - Include in token scope:
ON
- Name:
- Click “Save”
b. Team Scope
-
Create another client scope:
- Name:
team.scope - Description:
Restricts access to specific teams - Type:
Default - Display on consent screen:
ON - Include in token scope:
ON
- Name:
-
Add a hardcoded claim mapper:
- Name:
teams - Category:
Token mapper - Mapper Type:
Hardcoded claim - Claim name:
teams - Claim value:
["67d0aeb17172416c411d419e"] - Claim JSON type:
JSON - Add to ID token:
ON - Add to access token:
ON - Add to userinfo:
ON
- Name:
7. Assign Roles to Client Scope
- Navigate to the
gateway.readclient scope - Go to the “Scope” tab
- Assign both roles:
- Client role:
gateway_admin - Realm role:
gateway_admin_realm
- Client role:
8. Add Client Scopes to Client
- Navigate to the
linqra-gateway-clientsettings - Go to the “Client scopes” tab
- Add both scopes as “Default”:
gateway.readteam.scope
The configuration above is specific to the EC2 deployment environment. Make sure all URLs are using
https://linqra.com instead of localhost URLs.16. Useful Docker Commands and Maintenance
Check Running Containers
Check Disk Usage
Stop All Containers and Remove Docker Images
Restart or Build Specific Services
Restart only the Keycloak service:Test and Debug
Refresh routes:Let me know if you want to add more commands or explanations!

