Deploy a React App using Nginx

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 มิ.ย. 2024
  • In this video, I will show how to deploy a React application on an EC2 Instance using Nginx. React applications are SPAs hence Nginx is a good option to serve static files. I will also show how to install Nginx and NodeJS on the EC2 Instance.
    Once we have installed all the required modules, the next step is to clone the project, run the build script and start the Nginx Server.
    Code: github.com/enricop89/react-ap...
    00:00 Introduction
    00:42 Create React App
    01:07 Create React Routes
    03:19 Create EC2 Instance
    05:01 Install Nginx and NodeJS on the EC2 Instance
    06:42 Clone the Repo and build the Project
    09:15 Nginx Config explanation
    12:53 Conclusion
    If you want to learn more about DynamoDB and AWS Services, make sure to
    subscribe to the channel:
    TH-cam 🎥 - / @enricoportolan
    🌎 Find me here:
    Twitter - / enricop89
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 82

  • @User_jkjsbbk
    @User_jkjsbbk 2 ปีที่แล้ว

    Subscribed, thank you a lot, I have finally fixed my problem with building, great tutorial

  • @thevolcanick
    @thevolcanick 2 ปีที่แล้ว

    subscribed! keep it up Enrico. helpful video.

  • @dmontesa
    @dmontesa 2 ปีที่แล้ว +2

    Thank you so much for this. I've tried so many tutorials but this was just so well explained and right for my app. Thank you again.

  • @sgwong513
    @sgwong513 2 ปีที่แล้ว +1

    really appreciate for this video. I been searching around for hours on web on how to serve react app but couldn't get it. (written the nginx try_files wrongly) really grateful about this video, it worked perfectly as I needed. Nice video with clear explanation.

  • @1995taunus
    @1995taunus ปีที่แล้ว

    Thank you for the great lesson!

  • @steelangelariana
    @steelangelariana 2 ปีที่แล้ว +1

    This is one of the best tutorial to learn how to deploy your app! Thank you so much for sharing this!!

  • @crazyvolt1660
    @crazyvolt1660 ปีที่แล้ว +1

    Followed almost every website, but didn't work.
    I followed your defined steps and its running.
    Thank you, Sir

  • @d0m2288
    @d0m2288 7 หลายเดือนก่อน

    Great tutorial, thank you.

  • @jasonhumphrey2464
    @jasonhumphrey2464 2 ปีที่แล้ว

    Great Video!

  • @sergiyrudenko905
    @sergiyrudenko905 ปีที่แล้ว +3

    Thank you, Enrico! Great lesson! Works great.
    If someone has something that doesn't work, you can always debug it with Nginx logs.
    In my case, I had "/build" folder permission issues. Fixed it by giving the right permission.

    • @mnyandeni
      @mnyandeni 11 หลายเดือนก่อน

      how did you give it the right permissions ?

  • @njtuts5818
    @njtuts5818 2 ปีที่แล้ว

    very good clarification

  • @mohammadfalahi3369
    @mohammadfalahi3369 2 ปีที่แล้ว

    Awesome and Helpful

  • @CharlyBGood11
    @CharlyBGood11 ปีที่แล้ว

    I love you Friend! New suscriber here!! :D

  • @mihirdoshi1262
    @mihirdoshi1262 2 ปีที่แล้ว

    Thank you so much:)

  • @agustinfeijoo1462
    @agustinfeijoo1462 ปีที่แล้ว

    you are the best!

  • @SanketPatil
    @SanketPatil 2 ปีที่แล้ว

    Thanks for video

  • @Mahesha999
    @Mahesha999 ปีที่แล้ว

    Hey super thanks for this crisp video. Also, have you created video explaining starting application from subpath which you said you will at the end of this video?

    • @EnricoPortolan
      @EnricoPortolan  ปีที่แล้ว

      th-cam.com/video/6CjbezdbB8o/w-d-xo.html Sure

  • @_Mandal_
    @_Mandal_ 2 ปีที่แล้ว +4

    i am facing the same issue of loading welcome page

  • @nagarajkalakutagi5717
    @nagarajkalakutagi5717 2 ปีที่แล้ว

    Nice

  • @rankstrikers9187
    @rankstrikers9187 2 ปีที่แล้ว +2

    I have followed your steps and configured. Page rendered but login api call is not working after npm run build.
    That means package.json proxy is working in react whole project but not work in build.
    Can you explain what the exact issue?

  • @DuyTran-ss4lu
    @DuyTran-ss4lu 2 ปีที่แล้ว

    Great

  • @mohitchandra2680
    @mohitchandra2680 ปีที่แล้ว

    what did you press to save the react.conf file i.e DOS Format, Mac Format, Append, Prepend, Backup files, to Files? Please tell we the command you used

  • @ethangordon3935
    @ethangordon3935 10 หลายเดือนก่อน +1

    Is there a reason we don’t just point nginx to the build folder within our react application? Why make a new directory and copy?

  • @SSSWorldClass
    @SSSWorldClass 11 หลายเดือนก่อน

    For every code changes in react js do we need to rebuild and restart nginx again and again.?

  • @anonymoustv8604
    @anonymoustv8604 ปีที่แล้ว

    For me, There is no code inside my root div. The files are being loaded in my Network tab and even sources. My favicon is being displayed properly but no code inside my root div

  • @breaker__
    @breaker__ 4 หลายเดือนก่อน

    Latest node version isn't working (20) - any recommendations for specific node version to use?

  • @smdjunaid1064
    @smdjunaid1064 3 หลายเดือนก่อน

    i want to add different port for different project dirs......how plz explain this too

  • @yashtibrewal4259
    @yashtibrewal4259 2 ปีที่แล้ว

    thanks

  • @asmaaat6266
    @asmaaat6266 ปีที่แล้ว

    how can i deploy a reactjs project on the server if i have already the backend in the server

  • @mdshadab3470
    @mdshadab3470 2 ปีที่แล้ว

    Bro I'm new to linux just come for server part how should i give the root directory no idea

  • @user-ux1mz9ox6j
    @user-ux1mz9ox6j ปีที่แล้ว +3

    It shows the default nginx at the browser... kill me

  • @Rory-qu4cx
    @Rory-qu4cx 6 หลายเดือนก่อน

    Thanks! For anyone stuck on the Welcome Page - uncomment include /etc/nginx/sites-enabled/*, and anyone stuck on error 500 -> chmod +x each part of the path 'home/ubuntu/..../build'

  • @bhargavitummala7690
    @bhargavitummala7690 2 ปีที่แล้ว

    Hi, npm run build was not working even after npm i

  • @BP-qy2pb
    @BP-qy2pb 2 ปีที่แล้ว +4

    May I ask what's the difference between
    react + express + nginx
    vs
    react + nginx?

    • @EnricoPortolan
      @EnricoPortolan  2 ปีที่แล้ว +3

      Sure, in react + express + nginx express is acting as the web server, serve the React app and nginx is routing the traffic to express. In the other configuration, nginx is serving react as a static file so it’s acting as a “web server”

  • @tylertyler965
    @tylertyler965 10 หลายเดือนก่อน +1

    is it necessary to do npm install if I copy my build file directly from my machine to ec2? That seems like the only reason we need npm run build from it. my ec2 keeps freezing when I run npm run build, maybe the memory is too small :(

    • @igorpostoev2077
      @igorpostoev2077 3 หลายเดือนก่อน

      Same thing happening. Built locally

  • @amarjeetsingh5473
    @amarjeetsingh5473 11 หลายเดือนก่อน

    only working for home page but when clicking another link it is not working

  • @Klausenitzer
    @Klausenitzer 3 ปีที่แล้ว +4

    hey everything worked for me except the end result. I still just get the default Welcome to Nginx!
    Only thing I did differently was I did the create react app/create react routes last, would that have any affect?
    please let me know anything i can check

    • @EnricoPortolan
      @EnricoPortolan  3 ปีที่แล้ว

      Hey, did you run nginx reload to have your changes applied? if you have a Github repo I can have a look

    • @Klausenitzer
      @Klausenitzer 3 ปีที่แล้ว

      @@EnricoPortolan I did run the reload, i've just gone through it again but no luck.
      I did notice i did input the wrong root path during the last step, so corrected that but same result D:
      Might give the github repo thing a go but never used it.

    • @EnricoPortolan
      @EnricoPortolan  3 ปีที่แล้ว

      @@Klausenitzer ok another thing you can do is to check the difference between my repo and your code: github.com/enricop89/react-app-expressjs-nginx

    • @Klausenitzer
      @Klausenitzer 3 ปีที่แล้ว

      The problem isn't running the app though, it works fine locally like at the start of the video. It's just the end result when you are going to the IP of the server. Mine still just points to the Nginx default page.
      Seems like there is an additional step to point nginx to use the react.conf insted of the default file? I'm really not sure.

    • @tanphan2899
      @tanphan2899 3 ปีที่แล้ว +3

      @@Klausenitzer I am also having the same problem as you

  • @mathieugrosso93340
    @mathieugrosso93340 ปีที่แล้ว

    hello ! i have followed the tutorial but when launching on ec2 instance i get "500 Internal Server Error" does any one know why ? Thanks !

  • @inhVanongFEFICHN
    @inhVanongFEFICHN 10 หลายเดือนก่อน

    I have a question for you. I deploy on server Ubuntu and domain points to IP addresses. If i type ip address on browser, it is Ok but no routing when i type domain. Can you explain??

    • @EnricoPortolan
      @EnricoPortolan  10 หลายเดือนก่อน

      Have you added an A record on route 53 or on your DNS provider?

  • @balasubramaniam7904
    @balasubramaniam7904 8 หลายเดือนก่อน

    is this automatic deployment

  • @user-ux1mz9ox6j
    @user-ux1mz9ox6j ปีที่แล้ว

    Hey man, ec2, ubuntu 22.04 LTS require permission to approach the folder ( in video ubuntu).......... I spent time a lot man

    • @mnyandeni
      @mnyandeni 11 หลายเดือนก่อน

      how did you fix the permission issue ?

  • @jorgeramiroalarconvargas2580
    @jorgeramiroalarconvargas2580 ปีที่แล้ว

    can you make your terminal smaller XD

  • @felipperian6710
    @felipperian6710 ปีที่แล้ว

    I did everything that you explain. But, my server dont shows the react application. The server is showing a starter page called "Welcome to nginx!". Can you help me?

  • @edchelstephens
    @edchelstephens 2 ปีที่แล้ว

    Thank you Enrico. Do you have a video for deploying the same app with docker?

    • @EnricoPortolan
      @EnricoPortolan  2 ปีที่แล้ว

      Sure, check it out: th-cam.com/video/5lK_iFJsWv4/w-d-xo.html

  • @srappytrex3946
    @srappytrex3946 2 ปีที่แล้ว

    Why do we run "npm run build" then " npm i" then "npm run build" again?

    • @EnricoPortolan
      @EnricoPortolan  2 ปีที่แล้ว

      Probably I said it by mistake, you need only npm install & npm run build

    • @srappytrex3946
      @srappytrex3946 2 ปีที่แล้ว

      @@EnricoPortolan Thank you, this is indeed a very clear walk through, appreciate it alot pal! Yet I am still crying all over my error 500 after a night of testing T.T...could it be something related to that the npm start won't run in port 80?

  • @private6117
    @private6117 2 ปีที่แล้ว

    I have 500 internal error. Anyone could help

    • @ayeshazahid2421
      @ayeshazahid2421 ปีที่แล้ว

      same here im keep on getting the same error

  • @Ben-pv9yh
    @Ben-pv9yh 2 ปีที่แล้ว

    Why use an EC2? S3 with cloudFront is perfect for hosting static files. EC2 are so expensive

    • @EnricoPortolan
      @EnricoPortolan  2 ปีที่แล้ว +1

      I totally agree with you, in fact I made a video about it: th-cam.com/video/CQ8vzm1kYkM/w-d-xo.html. Unfortunately some companies don't have the technology stack to deploy on S3 with Cloudfront and they prefer to use EC2 instances.

  • @simranbanwait
    @simranbanwait ปีที่แล้ว

    bro have font size for ants

  • @vladislav_pikiner
    @vladislav_pikiner ปีที่แล้ว +1

    try_files $uri /index.html -- that`s what we neeeeeeeeed !!! ) TY SOOO MA

  • @22lordnik22
    @22lordnik22 ปีที่แล้ว

    Thanks! Redirecting the files to try_files $uri /index.html; fixed my Problem. Always got an 404-error.