Skip to main content

One post tagged with "API Gateway"

View All Tags

Master Website Hosting on Oracle Cloud: Effortless Setup with Object Storage and API Gateway!

· 7 min read

Introduction


In today's digital age, a strong online presence is crucial for businesses and individuals alike. Hosting your website on the cloud offers unmatched scalability, reliability, and performance. Oracle Cloud Infrastructure (OCI) provides a robust and cost-effective solution for website hosting using Object Storage and API Gateway. This blog will walk you through the entire process, offering insights, tips, and best practices for seamless website hosting on OCI.


Why Choose Oracle Cloud for Website Hosting?


  • Scalability: Easily scale your website as traffic grows without worrying about hardware limitations.
  • Cost-Effective: Pay only for the resources you use, with no upfront costs.
  • High Availability: With OCI's global data centers, ensure your website is always accessible.
  • Enhanced Security: Advanced security features like encryption, firewall, and monitoring.


Key Components for Website Hosting on OCI


  1. Object Storage: Used to store and serve static files like HTML, CSS, JS, and media.
  2. API Gateway: Acts as a reverse proxy, enabling secure and scalable access to your website.
  3. DNS Configuration: Ensures your domain points correctly to your hosted site.
  4. IAM Policies: Manage access and permissions securely.

Following diagram shows the architecture that will be setup:

Architecture Diagram


Step-by-Step Guide to Host Your Website on Oracle Cloud


1. Set Up an Oracle Cloud Account


  • Sign up for a free Oracle Cloud account, which includes free credits to get started.
  • Configure your tenancy, compartments, and IAM settings.

2. Create a Virtual Cloud Network (VCN)


A Virtual Cloud Network (VCN) is a customizable and private network in Oracle Cloud Infrastructure. It is a fundamental component for any cloud deployment, including hosting a website. Here's how to create a VCN using the Oracle Cloud VCN Wizard:


Steps to Create a VCN:


  1. Navigate to the VCN Dashboard: Go to the Networking section in the OCI console.
  2. Choose the VCN Wizard: The wizard simplifies the setup by automatically creating necessary components like subnets, route tables, internet gateways, and NAT gateways.
  3. Enter Network Details:
    • Name: 'StaticWebsiteVCN'
    • CIDR Block: '10.2.0.0/16'
    • Subnet Types: Public and Private subnets
    • Public Subnet CIDR: '10.2.1.0/24'
    • Private Subnet CIDR: '10.2.2.0/24'
    • Internet Gateway: Automatic creation
    • NAT Gateway: Configured for private subnet internet access
  4. Select Internet Connectivity: Ensure the Internet Gateway is configured for the public subnet, and the NAT Gateway is in place for private subnet resources.
  5. Review and Create: Double-check the configurations, ensure security lists and route tables are correctly set up, and create the VCN.

3. Configure Security Lists

Security lists act as virtual firewalls for your VCN subnets. To allow HTTP/HTTPS traffic, follow these steps:


  1. Access Security Lists: Navigate to the security lists associated with your public subnet.
  2. Add Ingress Rules:
    • Source Type: CIDR
    • Source CIDR: 0.0.0.0/0 (for public access)
    • Allowed Ports: 80 (HTTP) and 443 (HTTPS)
    • Port 22: Allow for SSH access if needed
  3. Save the Rules: Apply the changes to allow internet traffic to your web application.

4. Set Up Object Storage


Oracle's Object Storage is ideal for hosting static website files such as HTML, CSS, JS, and media files.


How to Create and Configure Object Storage:


  1. Create a Bucket:
    • Name: StaticWebsiteBucket
    • Storage Type: Standard
    • Set Object Versioning if needed
  2. Upload Files:
    • Manually upload files or use the Oracle CLI for batch uploads.
    • Create folders (e.g., CSS, JS, images) if needed.
    • Ensure all files are correctly named and accessible
  3. Generate Pre-Authenticated Requests (PARs):
    • Allow API Gateway to securely access files.
    • Set up read-only access to the entire bucket or specific files.
    • Maintain a list of PAR URLs for easy management and updating

5. Configure API Gateway


The API Gateway serves as the front-end for your hosted website. It handles routing, security, and resource management.


Steps to Set Up the API Gateway:


  1. Create an API Gateway:
    • Choose the public subnet from the VCN created earlier.
    • Configure API endpoints and deployment settings.
    • Define the deployment name and the route base path as '/'
  2. Define Backend Routes:
    • Map routes to Object Storage using the PAR URLs.
    • Configure paths for 'index.html', '.js', '.css', '*.jpeg', and other static assets.
    • Use wildcards to simplify routing, e.g., '.css', '.js', '*.jpeg'
  3. Deploy and Test:
    • Test the deployment by accessing the API endpoint via a browser.
    • Validate that all assets load correctly and that the website is fully functional.
    • Monitor API calls and traffic through the API Gateway dashboard

6. Set Up DNS and SSL


For a professional and secure website, setting up DNS and SSL is critical.


  1. DNS Configuration:
    • Point your domain to the API Gateway's public endpoint.
    • Use Oracle Cloud's DNS service or an external DNS provider.
    • Configure CNAME or A records as necessary
  2. Enable SSL (Optional):
    • Set up an SSL certificate on the API Gateway.
    • Configure HTTPS routing to secure all web traffic.
    • Consider using Let's Encrypt or a third-party SSL provider

Best Practices for Website Hosting on OCI


  • Use Caching: Implement caching strategies to reduce latency.
  • Monitor Performance: Set up alerts and dashboards for real-time monitoring.
  • Backup and Recovery: Regularly back up your Object Storage data.
  • Optimize Costs: Use lifecycle management policies to reduce storage costs.
  • Use Pre-Authenticated Requests Wisely: Only expose necessary files to reduce security risks.
  • Test Extensively: Before going live, thoroughly test all endpoints and resources

Common Pitfalls and Troubleshooting


  1. Deployment Issues: Ensure that the VCN and API Gateway are correctly configured.
  2. File Not Found Errors: Double-check the bucket paths and pre-authenticated request (PAR) links.
  3. Access Denied: Validate IAM policies and public access settings for Object Storage.
  4. SSL Certificate Issues: Verify SSL configuration on API Gateway if HTTPS is not working.
  5. Network Configuration: Ensure that security lists and route tables are not blocking traffic

Conclusion


Oracle Cloud offers a powerful platform for hosting websites with minimal effort and maximum benefits. By leveraging Object Storage and API Gateway, you can create a scalable, secure, and high-performance website hosting solution. Follow the steps outlined in this guide to master website hosting on Oracle Cloud and take your online presence to the next level.

Please reach out to us for any of your cloud requirements


Ready to take your cloud infrastructure to the next level? Please Contact Us

Additional Resources




🔚 Call to Action


Choosing the right platform depends on your organizations needs. For more insights, subscribe to our newsletter for insights on cloud computing, tips, and the latest trends in technology. or follow our video series on cloud comparisons.


Interested in having your organization setup on cloud? If yes, please contact us and we'll be more than glad to help you embark on cloud journey.


💬 Comment below:
How is your experience with Mac on EC2? What do you want us to review next?