Junius L
September 17, 2023
2 min read
Junius L
September 17, 2023
2 min read
In this tutorial, we will guide you through the process of deploying a Bun application to an Amazon EC2 instance and configuring Nginx as a reverse proxy to efficiently serve your application. This setup allows you to host your Bun application securely and reliably.
Before we begin, ensure you have the following prerequisites in place:
Launch an EC2 instance on AWS. Choose an appropriate Amazon Machine Image (AMI), instance type, and configure the security group to allow incoming traffic on necessary ports (e.g., HTTP port 80 and SSH port 22).
#!/bin/bash
yum update -y && yum install git nginx -y && systemctl enable --now nginxOnce your EC2 instance is running, connect to it using SSH:
ssh -i YourKey.pem ec2-user@YourEC2PublicIPPM2 requires Node.js
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
nvm install nodecurl -fsSL https://bun.sh/install | bashgit clone https://github.com/julekgwa/Elysia-with-Bun-runtime.gitcd Elysia-with-Bun-runtime
bun installbun add -g pm2pm2 start bun --name bun-prod -- devOpen /etc/nginx/nginx.conf:
sudo vi /etc/nginx/nginx.confAnd paste the following code:
server {
listen 80;
server_name _;
location / {
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}https://github.com/julekgwa/Elysia-with-Bun-runtime
In this tutorial, we have successfully deployed a Bun application to an Amazon EC2 instance and configured Nginx as a reverse proxy to efficiently serve the application. This setup ensures your Bun application is hosted securely and is ready for production use. You can further customize and scale this environment to meet your specific requirements.
Happy deploying!