You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a setup guide to host the server on AWS EC2. It's assuming you already have an account setup and know about free tier limitations.
143
+
#### Setting up EC2
144
+
1. Select the EC2 Launch Instance Wizard choose Ubuntu(22.04 x86) as your OS under AMI section.
145
+
2. Choose t2.micro instance if you want to stay within free tier or your preferred instance type and head to the next section. Keep configuration as default.
146
+
3. Select the storage you need, 20 GBs should be more than enough and it'll still stay under free tier. Go to next step and leave tags as default.
147
+
4. Configure the security group as follows:
148
+

149
+
5. Click next to choose your key pair.(You'll be connecting to SSH via this key so keep it safe, if you don't have one already generate a new one)
150
+
151
+
Now, we need to attach an Elastic IP to this instance, as instances are allocated only a dynamic IP, also free tier only allows 1 hour of use without an elastic IP.
152
+
153
+
1. Select Elastic IP in the navigation pane, and generate a new Elastic IP.
154
+
2. Associate this Elastic IP to the instance you've just created.
155
+
3. Go to your instance and copy this Elastic IP(you'll see it listed under the v4 IP address)
156
+
157
+
#### Setting up the EC2 instance
158
+
1. Locate your key.pem file you generated in step 5 and connect to your server by using SSH:
159
+
```
160
+
sudo ssh -i <pem file> ubuntu@<Public IP of the EC2 instance>
6. Next, create an Nginx virtual host configuration file to host your React app.
197
+
`nano /etc/nginx/conf.d/react.conf`
198
+
add this to the file:
199
+
`server {
200
+
listen 80;
201
+
listen [::]:80;
202
+
root /var/www/html/react/;
203
+
index index.html index.htm;
204
+
# MODIFY SERVER_NAME EXAMPLE
205
+
location / {
206
+
try_files $uri $uri/ =404;
207
+
}
208
+
}`
209
+
7. Restart nginx
210
+
`systemctl restart nginx`
211
+
212
+
####Setting up Docker
213
+
Refer this link for [setting up docker](https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository"setting up docker") (setup via repository).
214
+
After successfully installing docker switch to the Docker directory `cd playground/backend/docker`
215
+
and build the docker image `sudo docker build -t playground-prod .` .
216
+
217
+
#### Setting up the backend server
218
+
1. Go to the backend folder `cd playground/backend`.
219
+
2. Install pipenv to install packages from the pipfile
220
+
`sudo pip install pipenv`
221
+
3. Make a directory for virtual environment(this will be useful when setting up the service) using `mkdir .venv` and install all required modules using `pipenv install`
222
+
4. Start the server using:
223
+
```sudo pipenv run gunicorn --bind 0.0.0.0:5000 wsgi:app```
224
+
225
+
You'll now be able to use the app. You should also setup a service for the gunicorn server so that it starts automatically when the server boots.
226
+
227
+
#### Setting up the service
228
+
1. Create a service file for our app `sudo nano /etc/systemd/system/backend.service`
229
+
2. Write the following configuration:
230
+
```
231
+
[Unit]
232
+
Description=Gunicorn instance to serve backend for playground
0 commit comments