Skip to content

Sådan installeres ReactJS med Nginx på Ubuntu 22.04

Netcloud24
Cloud Infrastructure Expert
NetCloud24 Expert Guides Open the dedicated video page

Video transcript: NetCloud24 Expert Guides. Practical knowledge for a reliable cloud. Cloud and VPS expertise, security, performance, and step-by-step tutorials. Learn, deploy, and keep building with NetCloud24.

 

 

 

I denne vejledning vil vi gennemgå, hvordan du kan installere ReactJS og konfigurere Nginx som en webserver til at servere din React-applikation på en Ubuntu 22.04-server. Denne installation kan være særligt nyttig for brugere af en VPS-server.

Forudsætninger

  • Ubuntu 22.04 installeret på din server.
  • Root-adgang eller sudo-rettigheder.
  • Node.js og npm installeret.
  • Nginx installeret.

Trin 1: Opdater systemet

Først skal du opdatere dit system for at sikre, at alle pakker er opdaterede:

sudo apt update && sudo apt upgrade -y

Trin 2: Installer Node.js og npm

Installer Node.js og npm, hvis de ikke allerede er installeret:

sudo apt install nodejs npm -y

Trin 3: Opret en ny React-applikation

Brug Create React App til at oprette en ny applikation:

npx create-react-app my-app

Trin 4: Byg React-applikationen

Skift til din applikationsmappe og byg applikationen:

cd my-app
npm run build

Trin 5: Konfigurer Nginx til at servere React-applikationen

Opret en ny Nginx-konfigurationsfil:

Visual overview of Sådan installeres ReactJS med Nginx på Ubuntu 22.04
Visual overview: Sådan installeres ReactJS med Nginx på Ubuntu 22.04
sudo nano /etc/nginx/sites-available/my-app

Tilsæt følgende konfiguration til filen:

server {
        listen 80;
        server_name your_domain_or_IP;

        location / {
            root /path/to/my-app/build;
            index index.html index.htm;
            try_files $uri $uri/ /index.html;
        }
    }

Trin 6: Aktivér konfigurationen og genstart Nginx

Opret et symbolsk link til sites-enabled:

sudo ln -s /etc/nginx/sites-available/my-app /etc/nginx/sites-enabled/

Tjek Nginx-konfigurationen for fejl:

sudo nginx -t

Genstart Nginx for at anvende ændringerne:

sudo systemctl restart nginx

Afslutning

Dine ReactJS-applikationer er nu tilgængelige via din webbrowser. Naviger til:

http://your_domain_or_IP/

Denne løsning kan være særligt nyttig for dem, der ønsker at hoste deres React-applikation effektivt fra en VPS-server.

 

Windows VPS Deutschland

Windows VPS España

Windows VPS Nederland

Key topics covered in Sådan installeres ReactJS med Nginx på Ubuntu 22.04
Key topics covered in this NetCloud24 guide.

Windows VPS Italia

Windows VPS Portugal

VPS Windows Italia

Windows VPS

Windows VPS

Windows VPS Sverige

Windows VPS Norge

Windows VPS

Windows VPS Türkiye

Practical checklist for Sådan installeres ReactJS med Nginx på Ubuntu 22.04
Practical checklist for applying the guidance in this article.

Windows RDS (Remote Desktop Services)

Windows VPS

Sådan installeres ReactJS med Nginx på Ubuntu 22.04
Sådan installeres ReactJS med Nginx på Ubuntu 22.04
Explore more

More on this topic

Netcloud24
Netcloud24
Cloud Infrastructure Expert · NetCloud24

Comments are closed.