Otu esi etinye Sails.js Framework na Nginx na Rocky Linux 8

Ogbogu Okonji bụ usoro Javascript nke ị nwere ike iji mee ngwa ngwa wuo ụlọ ọrụ ahaziri ahazi maka Node.js. Ọ dị ka ihe owuwu MVC sitere na usoro ndị dị ka Ruby na Rails, mana site na nkwado dị mma maka ụdị ngwa weebụ na-emepe emepe dabere na data yana dakọtara na njedebe ndị ọzọ gụnyere Angular, React, iOS, Android, Windows Phone, na ọtụtụ ihe ọzọ.

N'ime nkuzi na-esote, ị ga-amụta ka esi etinye Sails.js wee nweta interface dabere na webụ site na ịwụnye na ịhazi Nginx reverse proxy setup na Rocky Linux 8.

Prerequisites

  • OS akwadoro: Rocky Linux 8.+.
  • Akaụntụ onye ọrụ: Akaụntụ onye ọrụ nwere sudo ma ọ bụ ohere mgbọrọgwụ.
  • Ngwungwu achọrọ: curl, gcc-c++, mee

Melite Sistemụ Ọrụ

Melite gi Nkume linux Sistemụ arụmọrụ iji hụ na ngwugwu niile dị adị adịla ugbu a:

sudo dnf upgrade --refresh -y

Nkuzi a ga-eji ya sudo iwu na na-eche na ị nwere ọnọdụ sudo.

Iji nyochaa ọkwa sudo na akaụntụ gị:

sudo whoami

Ihe atụ na-egosi ọkwa sudo:

[joshua@rockylinux ~]$ sudo whoami
root

Ka ịtọlite ​​akaụntụ sudo dị adị ma ọ bụ ọhụrụ, gaa na nkuzi anyị na Otu esi etinye onye ọrụ na Sudoers na Rocky Linux.

Iji mgbọrọgwụ akaụntụ, jiri iwu na-esonụ na paswọọdụ mgbọrọgwụ banye.

su

Advertisement


Wụnye dabere maka Sails.js

Ọrụ mbụ bụ ịlele ma ọ bụ wụnye ngwugwu ndị a site na ịme iwu na-esonụ.

sudo dnf install curl gcc-c++ make

Ihe atụ mmepụta:

Otu esi etinye Sails.js Framework na Nginx na Rocky Linux 8

ụdị Y, wee pịa Tinye igodo ịga n'ihu na ịwụnye ihe ndabere.

Ozugbo etinyere ihe ndabere ahụ, ị ​​ga-achọkwa ịwụnye Node.js.

Nkuzi a ga-etinye NPM 16, mana ị nwere ike ịgbanwe nke a ka ọ bụrụ ụdị ọzọ a ka na-akwado.

Nke mbụ, bubata ebe nchekwa Node.js site na iji iwu ọnụ na-esote.

sudo curl -fsSL https://rpm.nodesource.com/setup_16.x | sudo bash -

Ọzọ, wụnye Node.js.

sudo dnf install nodejs

Ihe atụ mmepụta:

Otu esi etinye Sails.js Framework na Nginx na Rocky Linux 8

ụdị Y, wee pịa Tinye igodo aga n'ihu.

N'oge nrụnye, a ga-akpali gị ibubata igodo GPG.

Ihe Nlereanya:

Otu esi etinye Sails.js Framework na Nginx na Rocky Linux 8

ụdị Y, wee pịa Tinye igodo ịga n'ihu na mezue nrụnye.

Ozugbo echichi mechara, nyochaa nrụnye ahụ site na ịlele nọmba nrụpụta ụdị.

node --version

Ihe atụ mmepụta:

v16.12.0

N'aka nke ọzọ, ọ bụrụ na ị na-achọ ụdị Node.js, gaa na nkuzi anyị Otu esi etinye Node.JS 14/16 & NPM na Rocky Linux 8.

Wụnye Sails.js

Akụkụ ọzọ nke nrụnye ga-eji NPM wụnye Sails.js. Iji mee nke a, jiri iwu na-esonụ.

sudo npm -g install sails

Ugbu a arụnyere Sails.js, nzọụkwụ ọzọ bụ ịmepụta ọrụ ọhụrụ nke ị nwere ike ịkpọ aha ihe ọ bụla masịrị gị, mana a ga-akpọ ya. "testapp" maka nkuzi .

Mbụ, mepụta ndekọ, nke nwere ike dị n'ebe ọ bụla. Naanị rịba ama ebe zuru oke maka ma emechaa maka ọrụ sistemu. Nkuzi a ga-eji akwụkwọ ndekọ www.

sudo mkdir -p /var/www/
cd /var/www/

Ka imepụta "testapp," jiri iwu na-esonụ.

sudo sails new testapp

A ga-ajụ ozugbo ka ịhọrọ ndebiri maka ngwa Sails gị.

Ihe Nlereanya:

Otu esi etinye Sails.js Framework na Nginx na Rocky Linux 8

pịnye 2 ma pịa Tinye igodo ịga n'ihu na mezue "testapp" okike.

Ihe Nlereanya:

Otu esi etinye Sails.js Framework na Nginx na Rocky Linux 8

Na-esote, ịnyagharịa wee malite "testapp" iji nwalee na nyochaa.

cd mytestapp
sudo sails lift

Ihe atụ mmepụta:

Otu esi etinye Sails.js Framework na Nginx na Rocky Linux 8

Iji pụọ, jiri ya (CTRL+C) iwu.


Advertisement


Mepụta faịlụ ọrụ sistemụ maka Sails.js

Iji nweta ma jikwaa ọrụ sistemụ maka Sails.js, ị ga-emerịrị faịlụ ọrụ sistemu.

Mepụta faịlụ ọrụ site na iji iwu a.

sudo nano /lib/systemd/system/sails.service

Na-esote, detuo na mado ndị na-esonụ.

[Unit]
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/var/www/testapp
ExecStart=/usr/bin/sails lift
Restart=on-failure

[Install]
WantedBy=multi-user.target

Rịba ama, ọ bụrụ na ị tinye ebe ndekọ aha Sail.js na ebe dị iche, jide n'aka na ị gbanwee "WorkingDirectory=/var/www/testapp" ụzọ na ọrụ sistemu.

Chekwaa faịlụ (Ctrl+O), wee pụọ (CTLR+X).

Ọzọ, bugharịa daemon sistemu.

sudo systemctl daemon-reload

Ọzọ, malite ọrụ Sails.js wee mee ka ọ malite na nrụgharị sistemụ:

sudo systemctl enable sails --now

Mwepụta ihe atụ ma ọ bụrụ na ọ ga nke ọma:

Created symlink /etc/systemd/system/multi-user.target.wants/sails.service → /usr/lib/systemd/system/sails.service.

Ugbu a nyochaa ọkwa nke ọrụ Sails.js site na iji iwu a.

systemctl status sails

Ihe atụ mmepụta:

Otu esi etinye Sails.js Framework na Nginx na Rocky Linux 8

Wụnye & Hazie Proxy Reverse

Wụnye Nginx

Nkuzi a ga-eji Nginx dị ka onye nnọchi anya maka iji Sails. Enwere ike iji proxies ndị ọzọ. Agbanyeghị, Nginx kwụ ọtọ na ntụkwasị obi na nchekwa na arụmọrụ karịa ọtụtụ nhọrọ ndị ọzọ.

Mbụ, wụnye ụdị Nginx ndabara nke dị na Rocky Linux 8 App iyi.

sudo dnf install nginx

Ihe atụ mmepụta:

Otu esi etinye Sails.js Framework na Nginx na Rocky Linux 8

ụdị "Y," wee pịa "Tinye igodo" ịga n'ihu na nwụnye.

Na-esote, nyochaa ụdị nrụpụta ma ọ bụrụ na nrụnye ahụ gara nke ọma.

sudo nginx -v

Ihe atụ mmepụta:

nginx version: nginx/1.14.1

Tupu ịga n'ihu, ị ga-amaliterịrị ọrụ Nginx.

sudo systemctl enable nginx --now

Mwepụta ihe atụ ma ọ bụrụ na ọ ga nke ọma:

Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.

Na-esote, nyochaa ọkwa ahụ iji jide n'aka na ọ dịghị mperi.

systemctl status nginx

Mmepụta ihe atụ ma ọ bụrụ na ihe niile na-arụ ọrụ nke ọma:

Otu esi etinye Sails.js Framework na Nginx na Rocky Linux 8

Hazie Nginx ka ọ bụrụ proxy reverse

Na-esote, mepụta ngọngọ nkesa (virtual host) maka ngwa Sails. Enwere ike ime nke a site na nchịkọta ederede ọkacha mmasị gị.

Ihe Nlereanya:

sudo nano /etc/nginx/conf.d/sails.conf

Ugbu a detuo na mado ihe ndị a site na ịmegharị ya "Example.com" ngalaba nke onwe gị.

server {
 listen       80;
 server_name  sails.example.com;
   location / {
     proxy_pass        http://localhost:1337/;
     proxy_set_header  Host $host;
     proxy_buffering   off;
   }
 }

Chekwaa faịlụ (Ctrl+O), wee pụọ (Ctrl + X).

Na-esote, nwalee nhazi faịlụ na-arụ ọrụ, ma ọ dịghị njehie.

sudo nginx -t

Mwepụta ihe atụ ma ọ bụrụ na enweghị mperi:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Ozugbo Nginx weghachiri ọkwa dị mma n'oge ule akọrọ, malitegharịa ọrụ ahụ.

sudo systemctl restart nginx

Advertisement


Hazie Iwu Firewall

Site na ndabara, ọ nweghị iwu firewall edobere na ọdụ ụgbọ mmiri 80 ma ọ bụ 443 mgbe ị na-etinye Nginx. Tupu ị gaa n'ihu, ịkwesịrị ịtọ iwu ndị a, nke a ga-adabere na ọdụ ụgbọ mmiri ị ga-eji, mana edepụtara nhọrọ niile.

Mepee ọdụ ụgbọ mmiri 80 ma ọ bụ HTTP:

sudo firewall-cmd --permanent --zone=public --add-service=http

Mepee ọdụ ụgbọ mmiri 443 ma ọ bụ HTTPS:

sudo firewall-cmd --permanent --zone=public --add-service=https

Bugharịa firewall iji mee mgbanwe ka ọ dị irè

sudo firewall-cmd --reload

Mara, ị nwere ike ịtọlite ​​HTTPS ma emechaa na nkuzi ma ọ bụrụ na ejighị n'aka.

Nweta Interface Webụ Sails.js

Ugbu a ị tinyela nke ọma ma hazie sails.js na Nginx dị ka proxy reverse, ị nwere ike imepe ngwa Sails.js gị site na ịga na ngalaba ị kwuru site na imepe ihe nchọgharị ịntanetị kachasị amasị gị wee dee ihe ndị a.

http://salis.example.com

Ọ bụrụ na ịga nke ọma, ị ga-ahụ Sails.js ndabara ọdịda ibe.

Ihe Nlereanya:

Otu esi etinye Sails.js Framework na Nginx na Rocky Linux 8

Ekele, ị tinyela Sails.js na Rocky Linux 8 nke ọma.


Advertisement


Chekwaa Nginx na ka anyị zoo SSL Asambodo efu

Dị ka o kwesịrị, ị ga-achọ ịgba ọsọ Nginx gị HTTPS na-eji asambodo SSL. Ụzọ kacha mma isi mee nke a bụ iji Ka anyị zoo, ikike asambodo efu, akpaaka na mepere emepe nke ndị Otu nyocha nchekwa ịntanetị anaghị akwụ ụgwọ (ISRG).

Mbụ, wụnye EPEL ebe nchekwa na mod_ssl ngwugwu maka ngwungwu emelitere nke ọma na nchekwa.

sudo dnf install epel-release mod_ssl -y

Na-esote, wụnye ngwugwu certbot dị ka ndị a:

sudo dnf install python3-certbot-nginx -y

Ozugbo arụnyere, gbanye iwu a ka ịmalite imepụta asambodo gị:

sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email you@example.com -d www.example.com

Nke a bụ ezigbo ntọala nke gụnyere ike HTTPS 301 redirects, Strict-Transport-Security nkụnye eji isi mee, na OCSP Stapling. Naanị jide n'aka na ịhazigharịa e-mail na ngalaba aha na ihe ị chọrọ.

Ugbu a URL gị ga-abụ HTTPS://sails.example.com kama HTTP://sails.example.com.

Rịba ama, ọ bụrụ na ị na-eji nke ochie URL HTTP, ọ ga-akpaghị aka redirect gaa na HTTPS.

Nhọrọ, ị nwere ike ịtọ ọrụ cron iji megharịa asambodo na-akpaghị aka. Certbot na-enye edemede nke na-eme nke a na-akpaghị aka, ma ị nwere ike ibu ụzọ nwalee iji jide n'aka na ihe niile na-arụ ọrụ site na ịme ọkụ ọkụ.

sudo certbot renew --dry-run

Ọ bụrụ na ihe niile na-arụ ọrụ, mepee windo crontab gị site na iji iwu njedebe na-esote.

sudo crontab -e

Na-esote, kọwaa oge mgbe ọ ga-emeghari onwe ya. Ekwesịrị ịlele nke a kwa ụbọchị na opekempe, ma ọ bụrụ na achọrọ ka emegharịa asambodo ahụ, edemede ahụ agaghị emelite asambodo ahụ. Ọ bụrụ na ịchọrọ enyemaka na ịchọta ezigbo oge ịtọ, jiri ya crontab.guru ngwá ọrụ efu.

00 00 */1 * * /usr/sbin/certbot-auto renew

Save (CTRL+O) wee pụọ (CTRL+X), na cronjob ga-enyere aka na-akpaghị aka.

Okwu na mmechi

N'ime nkuzi a, ị mụtala otu esi etinye Sails.js Framework wee mepụta proxy reverse Nginx iji nweta ngwa ahụ. N'ozuzu, e nwere ọtụtụ frameworks si n'ebe, ma Sails.js bụ otu na ọtụtụ na-enwe mmasị iji na kwesịrị anya.

Ahapụ a Comment