Deploy MERN STACK App with AWS EC2

Deploy MERN STACK App with AWS EC2



git repo:

Nginx Configuration

/etc/nginx/nginx.conf

user ubuntu;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

client_body_buffer_size 100k;
client_header_buffer_size 1k;
client_max_body_size 100k;
large_client_header_buffers 2 1k;
client_body_timeout 10;
client_header_timeout 10;
keepalive_timeout 5 5;
send_timeout 10;
server_tokens off;
#gzip on; on;

include /etc/nginx/conf.d/*.conf;
}

/etc/nginx/conf.d/default.conf

server {
#listen 80;
listen 80 default_server;
listen [::]:80 default_server;
server_name yourdomain.com;

access_log /home/ubuntu/client/server_logs/host.access.log main;

location / {
root /home/ubuntu/client/deploy;
index index.html index.htm;
try_files $uri /index.html;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection “1; mode=block”;
add_header Strict-Transport-Security “max-age=31536000; includeSubdomains;”;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

server_tokens off;

location ~ /.ht {
deny all;
}

}

35 thoughts on “Deploy MERN STACK App with AWS EC2

  1. I uploaded my frontend build folder to the deploys folder, but it doesn't show up on the server's public IPv4 address. It says "500 Internal Server Error Nginx"? what did I do wrong?

  2. hi, how did you handle some secret information like in /config file i have mongodb_URI and jwt secret key, how do you handle this without pushing to the github repo ?

  3. thank you so much! you're the only tutorial that offers enough details with visual explanation. that really helps!

  4. One of the beat video on Internet, thank you so much for this video brother, got some very useful help from this video

  5. when i edit the file show this error and not save
    "ngainx.conf" E212: Can't open file for writing

    how can solve it

  6. Frontend working fine, Backend not getting connected, I think many of us have this issue, I request John to help us all.

  7. Firstly, thank you very much for this one! secondly, I wanted to ask how you set the url of the backend in the client? localhost? the public ipv4? the private ? I managed to work only with the public.. <url>:5000/ what do you say? Thanks!

  8. 안녕하세요~항상 좋은 강의 감사합니다! 제가 John Ahn님의 이전강의들을 따라하면서 만든 리액트+노드앱을 배포했는데, 405에러가 나옵니다. 이번 영상에서 사용하신 코드와 비교해보니 /client/src/setupProxy.js파일 유무가 차이점인 것 같아요. 혹시 createProxyMiddleware(target: http://localhost:5000) 으로 되어 있는 부분을 수정해야 할까요??

  9. Can you share your draw.io file url with us so that we can take a look at it whenever we need help with things. I want to learn how i can host my own mongodb in EC2 instance…

  10. A MILLION ! A BILLION ! A TRILLION !! THANKS TO YOUUUU FOR CREATING THIS AWESOME TUTORIAL!! I was struggling since long on this thing. Deserves a like!! and bookmarked !!! 🎉🎉🎉🎉

  11. after running npm run build I get error:
    ./src/_actions/user_actions.js
    Attempted import error: 'BACK_SERVER_URL' is not exported from '../components/Config.js'.

  12. do you know why i would get a ERR_CONNECTION_REFUSED. The client isnt able to send data to my backend after starting the node server and database.

  13. Hi John, I follow the steps but with my own personal react app I made, and got an error 405 (Not Allowed). My client side works fine, but when access a page that sends request to backend, I get an error 405 (Not allowed) on the console. Any Ideas why? "POST http://1.124.56.789/graphql 405 (Not Allowed)"

  14. my mongodb atlas requires ip to be whitelisted. Which ip? Cause i have added my computer's ip and its not connecting through putty

  15. Help pls:-
    I have hosted and frontend is working fine but is not getting connected to backend that is if i perform any function like login singup no respond is coming.

  16. Hi John great video, Very detailed and much appreciated information. I'm ready to tackle this MERN stack deploy to AWS challenge now!

Leave a Reply

Your email address will not be published. Required fields are marked *