Karɓi VHosts da yawa tare da masu amfani daban-daban a cikin Nginx

Abu mafi mahimmanci a duniya lokacin da kake da sabar, shine tunani game da tsaro da ƙarin tsaro, ba za ka taɓa zama mai girman kai ba

Wani abu da aka saba da shi kuma BA KWANA da shawarar, shine yin amfani da mai amfani iri ɗaya don duk rumbun adana bayanai, mafi munin idan anyi amfani da tushen, wanda duk yadda abin ya wuce misali, akwai waɗanda suke (saboda yawan al'aura ko rashin sani) yi wannan, Na riga na yi magana game da dalilin da ya sa BA za ku yi irin wannan a ciki ba wani matsayiYanzu lokaci ya yi da za a bayyana yadda kuma me ya sa ya fi kyau a raba aiki da sabar yanar gizo a cikin masu amfani daban-daban, wannan lokacin za a yi amfani da ita Nginx.

SadaukarServer_SubImage

Menene na masu amfani da sabar yanar gizo?

Don bayyana shi a taƙaice kuma a hanya mai sauƙi, sabar yanar gizo (apache, nginx, duk abin da) ke buƙatar buɗe matakai a cikin tsarin, hanyoyin da zasu kasance sune ke karɓar fayiloli daga HDD (hotuna, da sauransu) kuma suka sanya su samuwa ga burauzar mai binciken. Sabar yanar gizo ba zata iya daukar fayilolin kawai ta sarrafa su ba kowa ba, ma'ana, yana buƙatar mai amfani wanda shine zai yi duk wannan a ƙarshe, kuma wannan mai amfani shine wanda nake magana akansa, shin an fahimta kenan?

Mene ne keɓancewa a cikin masu amfani da yawa?

Bari muyi tunanin cewa akan sabar mu muna da rukunin yanar gizo 2, namu wanda aikin sirri ne, da kuma wani (muyi tunanin budurwarmu ce ko kannenmu). Ko da lokacin da muke amfani da bayanai na daban da masu amfani daban don samun damar su, a ƙarshe fayilolin rukunin yanar gizon guda biyu ana amfani da su ta mai amfani ɗaya, mai amfani ɗaya ne ke sarrafa aikin PHP don dukkan rukunin yanar gizo (yawanci www-data ne). Wannan aiki ne da ba a ba da shawarar ba, yana da kyau a raba komai da kyau, kamar yadda tsohuwar magana take, yana da kyau a zauna lafiya fiye da yin haƙuri.

Ok Na fahimta, yaya zanyi da Nginx

2000px-Nginx_logo.svg

Abu na farko da za a lura da shi shine Nginx bashi da wani tsari da yake sarrafa aiki na PHP kamar yadda Apache keyi, don Nginx muna buƙatar amfani da PHP-CGI ko PHP-FPM, wanda yake aiki daidai (ko mafi kyau) fiye da Apache. Don haka, don raba aikin PHP tsakanin masu amfani daban, zamu buƙaci canza layi a cikin fayilolin sanyi na PHP (CGI ko FPM), ba Nginx kanta ba.

A ce ka yi amfani da shi PHP-FPM, za mu ƙirƙiri fayil ɗin sanyi na pool Don takamaiman shafin, ma'ana, wurin wanka shine hanya don raba aikin PHP daga PHP-FPM, amma muna tafiya cikin ɓangarori.

1. Da farko dole ne mu san wane ne mai amfani da tsarin da zamu yi amfani da shi, zan ɗauka cewa har yanzu bamu da wata halitta kuma da kyau ba, bari mu ƙirƙira ta:

Duk waɗannan umarni masu zuwa dole ne a kashe su tare da gatanan gudanarwa, ko dai tare da tushe kai tsaye ko amfani da sudo

adduser blog

Za mu fara aikin yau da kullun don ƙirƙirar mai amfani, shigar da kalmar sirri, da dai sauransu.

Na sanya mai amfani don kawai in bi misali, cewa rukunin yanar gizon da zamu fara tallatawa zai zama blog, da kyau cewa ... don sanin kowane mai amfani da wane shafin yake da alaƙa

1. Da farko bari muje zuwa /etc/php5/fpm/pool.d/:

cd /etc/php5/fpm/pool.d/

2. Yanzu, zamu ƙirƙiri fayil da ake kira blog.conf:

touch blog.conf

3. Yanzu zamu sanya sanyi na wurin waha wanda zamuyi amfani dashi don VHost blog:

Shirya fayil din blog.conf tare da Nano ... misali: sudo nano blog.conf
[blog] mai amfani = blog
kungiya = blog
saurare = / var / run / php5-fpm-blog.sock listen.owner = blog
saurare.group = blog
pm = ondemand pm.max_children = 96 chdir = /

Note: Abinda nake musu alama a jan shine abinda yakamata su canza dangane da mai amfanin da suka ƙirƙira a baya. Misali, idan sun kirkiri wani VHost tare da wani mai amfani (dandali misali) to a maimakon sanya kawai shafin yanar gizo a kowane layi, shin an fahimta?

4. Da zarar sanyi na sabon wurin waha (fayil din blog.conf wanda muka kirkireshi kuma muka gyara shi), shine lokacin da za'a gaya wa Nginx VHost yayi amfani da sock daban don wannan VHost, don wannan rukunin yanar gizon. Sock ɗin da za'a yi amfani da shi shine wanda muka bayyana a baya (/var/run/php5-fpm-blog.sock). Bari mu shirya Nginx VHost kuma a cikin aikin sarrafa PHP, muna nuna amfani da safa. Misali:

wuri ~ \ .php $ {idan (! -f $ request_filename) {dawo da 404; }
fastcgi_pass unix: / var / gudu / php5-fpm-blog.kafa;
hada da fastcgi_params; fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name; fitowar sauri-kara-lokaci_ 300; }

Kamar yadda kuke gani, Ina nuna cewa aikin PHP na VHost ɗin (waɗancan layukan sune misali ciki / sauransu / nginx / shafuka-kunnawa / vhost-blog) yi shi tare da safa da aka samo a cikin /var/run/php5-fpm-blog.sock ... wanda shine wanda muka ƙirƙira a baya lokacin gyara /etc/php5/fpm/pool.d/blog.conf ... shine ba a fahimta ba?

5. Da zarar an gama wannan, za mu sake farawa ayyukan biyu (php5-fpm da nginx) da voila, za mu ga cewa sarrafa wannan rukunin yanar gizon (vhost) BA a yin shi ta hanyar www-data ko tushe ko wani mutum makamancin haka, amma ta mai amfani cewa mu wanda aka ayyana a baya

Anan zan nuna muku fitowar wani ps aux | grep fpm a kan ɗaya daga cikin sabar kuɗina:

ps aux | grep fpm ebook 586 0.0 0.0 349360 1204? S Mar30 0:00 php-fpm: pool ebook ebook 589 0.0 0.0 349360 1204? S Mar30 0:00 php-fpm: pool ebook www 608 0.0 0.2 350084 5008? S Mar30 0:00 php-fpm: pool www www 609 0.0 0.2 350600 5048 30? S Mar0 00:3 php-fpm: pool www tv611 0.0 0.0 349360 1204 30? S Mar0 00:3 php-fpm: pool tv3 tv615 0.0 0.0 349360 1204 30? S Mar0 00:3 php-fpm: pool tv1818 mujallar 1.7 1.7 437576 36396 09? S 55:0 46:2264 php-fpm: mujallar mujallar mujallar 1.9 1.7 437332 35884 10? S 15:0 26:2338 php-fpm: dalibin mujallar pool 4.3 1.0 428992 22196 10? S 18:0 53:2413 php-fpm: mujallar ɗalibin ɗalibai 1.8 1.7 437764 36152 10? S 22:0 18:2754 php-fpm: mujallar gutl magazine 3.5 1.3 356724 27164 10? S 38:0 00:5624 php-fpm: wurin waha gutl cgr 0.0 1.0 365168 22696 28? S Apr0 16:7900 php-fpm: ɗalibin cgr 0.3 2.5 457052 52444 25? S Apr20 23:11021 php-fpm: dalibin poolil 0.4 2.5 458316 52864 28? S Apr5 57:11254 php-fpm: ɗalibin ɗaliban cgr 0.0 1.0 363152 21708 28? S Apr0 12:13184 php-fpm: tafkin cgr cgr 0.0 1.0 362872 21360 28? S Apr0 08:XNUMX php-fpm: tafkin cgr

Kamar yadda kake gani ... raba aikin PHP ta masu amfani ta amfani da Nginx + PHP-FPM abu ne mai sauki da gaske, a can ka ga cewa akwai wuraren waha da yawa, tunda akwai masu amfani da yawa.

ƘARUWA

Idan ya zo ga sabobin, baku taba isa ba ... tsaro ba abu bane da za ayi wasa da shi, gwargwadon kokarinmu na inganta tsaro na sabobinmu da aiyukan su, da alama wataƙila (mai nasara) zamu firgita. yunƙurin hack ko wani abu makamancin haka 😉


Abubuwan da ke cikin labarin suna bin ka'idodinmu na ka'idojin edita. Don yin rahoton kuskure danna a nan.

9 comments, bar naka

Bar tsokaci

Your email address ba za a buga.

*

*

  1. Mai alhakin bayanan: Miguel Ángel Gatón
  2. Dalilin bayanan: Gudanar da SPAM, gudanar da sharhi.
  3. Halacci: Yarda da yarda
  4. Sadarwar bayanan: Ba za a sanar da wasu bayanan ga wasu kamfanoni ba sai ta hanyar wajibcin doka.
  5. Ajiye bayanai: Bayanin yanar gizo wanda Occentus Networks (EU) suka dauki nauyi
  6. Hakkoki: A kowane lokaci zaka iyakance, dawo da share bayanan ka.

  1.   nisanta m

    Gaara, a halin yanzu waɗannan abubuwan yakamata su zama masu sarrafa kansu yadda yakamata, ina ba ku shawara ku gwada Ansible. Ba tare da wakili ba, kawai kuna buƙatar python ne a kan runduna mai nisa, mai sauƙin daidaitawa, fayilolin yaml, samfuran Jinja.

    https://github.com/ansible/ansible-examples/tree/master/wordpress-nginx

    1.    KZKG ^ Gaara m

      Bari mu gani, wannan ba koyaushe bane kawai ga rukunin yanar gizo na WordPress, kuma ... haha ​​watakila Ana iya latsa volao, amma na fi son sanin daidai yadda komai yake aiki a sabar, koda kuwa zan kashe minti 1 na kirkirar sabbin safa da sabon VHost 😀

      1.    nisanta m

        Da sauki zaka iya sarrafa komai, kayi kusan duk abinda kake so, amfanin wannan hanyar shine ka lullube aikin sannan ka aiwatar da yadda kake so, kaga cewa kana da wani shafi mai dauke da kaya kuma kana son yin aikin daidaita kaya tsakanin sabobin aikace-aikace, wadannan dole ne a daidaita ku daidai ba za ku iya tsallake mataki ba ko yin wani abu daban a ɗayan su, shin za ku iya tunanin yin aikin mataki-mataki sau 4? Tare da Amsali yana da sauƙi kamar ƙara sunan masauki a cikin fayil ɗin kaya da Voilá !!

        http://www.ansible.com/how-ansible-works

      2.    nisanta m

        Yi haƙuri game da ƙungiyar Ansible, amma ɗayan waɗannan fasahohin ne kuka gano kuma kuna son kowa yayi amfani da shi yanzu saboda yana da kyau da aiki, yana kama da lokacin da kuka gano NGINX kuma kuna son duk abokanka su bar Apache kai tsaye.

        https://speakerdeck.com/slok/ansible-all-the-things

  2.   Tushen 87 m

    Ni (ko karatu zan kasance) mai haɓakawa kuma tare da NGIX Na sami matsaloli da yawa lokacin daidaitawa nginx + php-fpm. Na san cewa archlinux distro ba shine mafi kyau don sanya shi azaman saba ba, amma duk lokacin da na sabunta sigar na ngix ko php komai sai ya faɗi don haka na daina yunƙurin lol ... A yau ina tare da Apache + na yau da kullun PHP amma zan gani idan na sake zagaya NGIX ... watakila a cikin wata na’ura ta kama

    1.    nisanta m

      Hankalin ya canza kaɗan, nginx yayi aiki da tsayayyen abun kuma yayi aiki azaman wakili na baya ga php-fpm shine wanda ke gudanar da ainihin PHP, dole ne ku fara cikin ɓangarori kuma ku cimma ƙaddamarwa mataki-mataki, nemi jagora don turawa tsarin aikin da kuke aiki da shi, kowane ɗayan yana da cikakken bayanin sa da sunan jama'a, a tsaye, albarkatu, da sauransu ...

  3.   m m

    Shin al'umma sun sami babbar ni'ima ta barin kalmar "hostear", wacce babu ita. Wallahi tallahi, da wuya kace "mai gida"?

  4.   Wil m

    Gaisuwa, bin misalin ku Ina so in sani ko za'a iya yin wurin wanka kawai don backpress na wordpress, ma'ana, don wp-admin suna yin sabon soket don haɗin haɗi zuwa bayan

    wuri / wp-admin {
    tushen /var/www/yoursite.com/wp-admin;
    index index.php index.html index.htm;
    wuri ~ ^ / wp-admin /(.+. php) $ {
    try_files $ fam = 404;
    tushen /var/www/yoursite.com/wp-admin;
    sun haɗa da / sauransu / nginx / fastcgi_params;

    fastcgi_pass server unix:/run/php5-fpm2.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 256 4k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_read_timeout 1240;
    }
    location ~* ^/wp-admin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
    root /var/www/tusitio.com/wp-admin/;
    }
    }

bool (gaskiya)