Cov txheej txheem:

Yuav Ua Li Cas Qhia Tawm Web-Server Nrog Raspberry Pi: 10 Kauj Ruam
Yuav Ua Li Cas Qhia Tawm Web-Server Nrog Raspberry Pi: 10 Kauj Ruam

Video: Yuav Ua Li Cas Qhia Tawm Web-Server Nrog Raspberry Pi: 10 Kauj Ruam

Video: Yuav Ua Li Cas Qhia Tawm Web-Server Nrog Raspberry Pi: 10 Kauj Ruam
Video: UA LI CAS THIAJ TSI MUAJ MENYUAM 2024, Kaum ib hlis
Anonim
Yuav Ua Li Cas Qhia Tawm Web-Server Nrog Raspberry Pi
Yuav Ua Li Cas Qhia Tawm Web-Server Nrog Raspberry Pi

Phau ntawv qhia no yuav qhia koj li cas kom tau txais koj li Raspberry Pi los tuav lub vev xaib-server, uas tuaj yeem siv rau hosting cov vev xaib, thiab txawm tias hloov kho me ntsis los tuav ntau lwm yam kev pabcuam online xws li game servers, lossis video streaming servers. Peb yuav tsuas yog npog yuav ua li cas los tuav lub web-server yooj yim yam tsis tau kho lub pob ua ntej.

Cov Ntaub Ntawv Yuav Tsum Tau:

  • Raspberry Pi (Peb Pom Zoo Raspberry Pi 3 Qauv B+ raws li uas tau ua hauv wireless txuas)
  • Kev siv internet
  • SD Card (Pom zoo 32GB, Yam tsawg kawg 8GB)
  • USB Keyboard
  • USB Mus
  • HDMI Cable
  • HDMI muaj peev xwm Saib
  • Nkag mus rau koj lub router teeb tsa vaj huam sib luag (Qhov no yog rau kev xa mus rau chaw nres nkoj)

Kauj Ruam 1: Pib Pib Koj Raspberry Pi

Pib koj li Raspberry Pi
Pib koj li Raspberry Pi

Ntxig Micro SD daim npav rau lwm lub tshuab, thiab Nruab Raspbian OS rau nws siv cov lus qhia pom ntawm https://www.raspberrypi.org yog tias koj tab tom pib nrog ib qho tshiab. Txwv tsis pub, xyuas kom koj daim npav Micro SD tau ntxig rau hauv koj li Raspberry Pi.

Kauj Ruam 2: Nqa Koj Cov Khoom Siv thiab Nkag Mus Rau

Nqa koj cov khoom siv sab nrauv thiab nkag mus
Nqa koj cov khoom siv sab nrauv thiab nkag mus

Plug rau hauv tus saib xyuas siv HDMI cable, ntsaws rau hauv koj lub keyboard USB, ntsaws koj lub USB nas thiab lub zog txuas rau Raspberry Pi.

Nkag mus rau hauv Pi ib zaug nws tau pib ua haujlwm siv lub npe siv thiab tus lej zais yog tias thov. Thawj lub npe siv yog "pi" thiab thawj tus password yog "raspberry".

Kauj Ruam 3: Txuas Raspberry Pi mus rau Is Taws Nem

Yog tias koj nkag tau rau Ethernet cable yooj yim ntsaws nws thiab koj zoo mus.

Yog tias koj siv Wifi, muaj ob peb txoj hauv kev sib txawv los ua kom tiav qhov no. Phau ntawv qhia no yuav ua raws lub davhlau ya nyob twg qhov txheej txheem kom ntseeg tau, txawm tias koj tsis siv Raspbian's GUI, koj tseem tuaj yeem txuas tau.

  1. Qhib Terminal Terminal yog tias koj siv GUI.

    raws qhov bar nyob rau sab saum toj ntawm nplooj ntawv, lub davhlau ya nyob twg nyob ntawd

  2. Xyuas kom koj Raspberry Pi pom Wifi

    1. Nkag mus hais kom ua `sudo iwlist wlan0 scan`
    2. Nrhiav koj qhov chaw nkag

      1. ESSID yog lub npe ntawm qhov chaw nkag
      2. IE yog qhov kev lees paub siv.
  3. Nkag mus hais kom ua `wpa_cli` txhawm rau teeb tsa qhov nkag mus.
  4. Nkag mus 'add_network`

    1. Qhov no ntxiv lub network tshiab rau koj cov npe teeb tsa.
    2. Qhov no rov qab tus lej tus lej hauv lub qhov rai davhlau ya nyob twg. Thawj lub network suav nrog '0', thiab phau ntawv qhia no xav tias koj tau teeb tsa thawj lub network. Yog tias qhov no tsis yog, hloov tus lej uas nyob hauv cov lus txib nrog ib qho lus txib no rov qab los.
  5. Kho lub network tshiab

    1. Sau `set_network 0 ssid" ESSID "`

      1. Hloov ESSID nrog lub npe ntawm qhov chaw nkag. Xyuas kom meej tias lub npe nkag lub npe nyob hauv cov lus hais tawm.
      2. Nco ntsoov, yog tias koj cov lus txib add_network xa rov qab tus lej uas tsis yog 0, hloov 0 hauv qhov hais kom ua nrog tus lej twg uas tau xa rov qab
    2. Sau `set_network 0 psk" PASSWORD "`

      1. Hloov PASSWORD nrog tus password ntawm qhov nkag mus. Xyuas kom meej tias tus lej nkag nkag lo lus zais nyob hauv nqe lus.
      2. Nco ntsoov, yog tias koj cov lus txib add_network xa rov qab tus lej uas tsis yog 0, hloov 0 hauv qhov hais kom ua nrog tus lej twg raug xa rov qab.

  6. Txuas mus rau lub network los ntawm kev nkag mus rau cov lus txib `select_network 0`

    Nco ntsoov, yog tias koj cov lus txib add_network xa rov qab tus lej uas tsis yog 0, hloov 0 hauv qhov hais kom ua nrog tus lej twg raug xa rov qab

  7. Tawm hauv daim ntawv thov los ntawm kev ntaus ntawv "tawm"

Kauj Ruam 4: Txheeb Xyuas Koj Tus Pi Yog Qhov Tshiab

Tsis pub dhau koj lub davhlau ya nyob twg qhov rai, hloov kho koj daim ntawv teev npe pob los ntawm kev ntaus ntawv 'sudo apt -tau hloov tshiab -y'.

Tom ntej hloov kho txhua pob khoom teeb tsa los ntawm kev ntaus ntawv 'sudo apt-get dist-upgrade -y'.

Kauj Ruam 5: Nruab NodeJS rau ntawm Pi

Tsis pub dhau lub davhlau ya nyob twg lub qhov rai, peb yuav tsum teeb tsa NodeJS uas yog kev ua haujlwm ntawm server-sab ntawm JavaScript. Express siv NodeJS los khiav. Txhawm rau nruab NodeJS peb xav tau apt-tau nws mus rau Pi. Nkag mus 'sudo apt -tau nruab nodejs -y'. Xyuas kom NodeJS tau teeb tsa los ntawm kev nkag mus 'nodejs -v' kom tau txais tus lej version tam sim no teeb tsa.

Tom qab NodeJS tau teeb tsa, peb yuav tsum teeb tsa Node Pob Tus Thawj Tswj. Nov yog pob tus thawj tswj hwm uas ua haujlwm nrog NodeJS txhawm rau teeb tsa cov qauv, xws li ExpressJS. Nkag mus 'sudo apt -tau nruab npm -y'. Xyuas kom NPM raug teeb tsa los ntawm kev ntaus ntawv 'npm -v' kom tau txais tus lej version tam sim no teeb tsa.

Kauj Ruam 6: Nruab Express thiab Express Generator

Thaum npm tau teeb tsa, Hom "sudo npm install express -g". Qhov no rub tawm ExpressJS hauv pob tus thawj tswj hwm cov npe hauv ntiaj teb, yog li koj tuaj yeem khiav Express hauv ib qho ntawv twg.

Tom ntej no, ntaus "sudo npm install express -generator -g". Qhov no yog lub tshuab hluav taws xob nthuav tawm sai sai, uas zoo heev rau teeb tsa lub vev xaib sai.

Kauj Ruam 7: Khiav Cov Hluav Taws Xob Express

Ntaus `sudo express myapp`. Koj tuaj yeem hloov "myapp" nrog txhua yam uas koj xav tau rau npe koj lub vev xaib.

Qhov no tsim cov ntawv tais ceev tseg nrog cov ntaub ntawv tsim nyog xav tau los nthuav qhia kom khiav.

Lub cav pom lub neej ntawd yuav yog Pug.

Nws tau pom zoo kom saib mus rau lwm txoj hauv kev, thiab koj tuaj yeem ua dab tsi nrog Express.

Thaum lub tshuab hluav taws xob nthuav tawm tiav, koj tuaj yeem sim saib seb lub web server ua haujlwm li cas. Ntaus `cd myapp` khiav `npm kom nkag mus rau hauv daim nplaub tshev uas tau tsim, tom qab ntawd ntaus ntawv 'npm pib' uas yuav ua rau daim ntawv thov.

Siv lub chaw nres nkoj pib, qhib lub vev xaib thiab mus rau localhost: 3000. Koj yuav tsum pom 'Express, Zoo Siab Tos Txais Express'. Koj tau ua tiav tsim qhov Express web server.

Kauj Ruam 8: Teeb Tus Neeg rau zaub mov kom Ua Haujlwm ntawm Boot-up

Kho cov ntaub ntawv rc.local. Cov ntaub ntawv no khiav txhua lub sijhawm Pi khau raj

Ua qhov no los ntawm kev ntaus "sudo nano /etc/rc.local"

Ua ntej kab "tawm 0" ntxiv cov kab hauv qab no: "su pi -c 'node /home/pi/myapp/server.js </dev/null $'"

Hloov qhov 'myapp' ib feem ntawm cov ntawv tais ceev tseg nrog txhua yam uas koj lub npe koj lub vev xaib ua.

Txuag cov ntawv los ntawm kev ntaus CTRL + x.

Kauj Ruam 9: (YOOJ YIM) Kev xa mus

(TSIS MUAJ) Portforwarding
(TSIS MUAJ) Portforwarding

Nov yog cov kauj ruam tseem ceeb yog tias koj xav kom koj lub web server tuaj yeem saib tau los ntawm sab nraum koj lub tsev lossis tsev kawm ntawv network. Cov txheej txheem no yuav txawv nyob ntawm tus router, tab sis lub tswv yim nyob ib yam. Koj tuaj yeem nrhiav cov lus qhia tshwj xeeb rau koj lub router ntawm no https://portforward.com/router.htm siv koj tus qauv routers tus lej. Daim duab saum toj no qhia qhov piv txwv ntawm lub vev xaib-nplooj ntawv yuav zoo li cas, coj los ntawm portforward.com

  1. Nkag mus rau koj lub routers tswj vaj huam sib luag
  2. Sau 2 daim ntawv ntawm cov ntaub ntawv, koj tus raspberry pi tus IP chaw nyob sab hauv, thiab sab nraud IP chaw nyob ntawm tus router

    1. Tus IP chaw nyob sab hauv ntawm pi tuaj yeem pom los ntawm kev ntaus "sudo ip addr show" hauv lub davhlau ya nyob twg
    2. Tus IP sab nraud tuaj yeem nrhiav tau los ntawm kev ntaus "Kuv tus IP chaw nyob yog dab tsi" hauv google.
  3. Sab hauv ntawm koj lub router teeb tsa vaj huam sib luag koj xav teeb tsa txoj cai siv sab hauv IP chaw nyob ntawm raspberry pi
  4. xaiv TCP thiab rau qhov chaw nres nkoj koj tuaj yeem siv qhov chaw nres nkoj twg koj teeb tsa ntawm koj lub node server hauv qhov nthuav qhia app, peb siv 1337

Kauj ruam 10: Nkag mus rau lub vev xaib

Tam sim no koj tuaj yeem nkag mus rau koj lub web-server los ntawm qhov chaw nyob deb, sim nws tsuas yog ntaus https:// INTERNAL_IP_ADDRESS: 1337, nco ntsoov hloov "INTERNAL_IP_ADDRESS" nrog IP sab nraud yog tias koj nkag mus rau lub web-server los ntawm sab nraud network, lossis siv Tus IP sab hauv yog tias koj nkag mus tau los ntawm hauv tib lub network.

Pom zoo: