Adding CORS Header for a OpenLiteSpeed RunCloud Server: A Step-by-Step Guide

Adding CORS Header for a OpenLiteSpeed RunCloud Server: A Step-by-Step Guide

 

Introduction

Cross-Origin Resource Sharing (CORS) is a crucial mechanism that allows web browsers to securely access resources on different domains. If you're using the OpenLiteSpeed server with RunCloud as your hosting panel, you may need to add CORS rules to your LiteSpeed configuration. In this blog post, we will guide you through the process of adding CORS rules in the LiteSpeed configuration using RunCloud.


Step 1: Accessing RunCloud Panel

To begin, log in to your RunCloud account and navigate to the Web Applications section.


Step 2: Selecting the Web Application

Choose the web application for which you want to add the CORS rules from the list of available applications.


Step 3: Modifying LiteSpeed Configuration

Once you have selected the web application, click on the LiteSpeed Config option. This will open the LiteSpeed configuration editor.


Step 4: Adding the CORS Rule

In the LiteSpeed configuration editor paste below code. Add the following line:

context / {
extraHeaders Access-Control-Allow-Origin *
}


This rule allows requests from any domain by adding the Access-Control-Allow-Origin header with the value * (wildcard). If you want to restrict access to specific domains, you can replace the * with the desired domain(s) separated by commas.


Step 5: Restarting the LSWS Service

After adding the CORS rule, it's important to restart the LSWS service for the changes to take effect. Look for the Restart option within the server service section. This will initiate the restart process. Otherwise, you can run below command

service lsws-rc restart


Conclusion:

Enabling Cross-Origin Resource Sharing (CORS) is crucial for ensuring secure and controlled access to resources on your web application. By following the steps outlined in this blog post, you can easily add CORS rules to your OpenLiteSpeed server using the RunCloud hosting panel. Remember to restart the LSWS service after making the necessary changes in the LiteSpeed configuration. This will ensure that the added CORS rules are properly applied.


Comments