Bamba ama-VHost amaningi nabasebenzisi abahlukile ku-Nginx

Into ejwayelekile emhlabeni uma unesiphakeli ukucabanga ngezokuphepha nokuvikeleka okwengeziwe, awusoze waba neparanoid ngokwanele 😉

Umkhuba ojwayelekile futhi AKUKHO okunconyiwe, ukusebenzisa umsebenzisi ofanayo kuwo wonke ama-database, kubi uma kusetshenziswa izimpande, okungahle kubonakale kungakholeki, kukhona labo (ngenxa yobufebe noma ukungazi) yenza lokhu, bengivele ngikhulume ngokuthi kungani UNGENZAKALO unje omunye okuthunyelweManje yisikhathi sokuchaza ukuthi kungani futhi kungani kungcono ukuhlukanisa ukucutshungulwa kweseva yewebhu kubasebenzisi abahlukene, kulokhu kuzobe kusetshenziswa Nginx.

I-DedicatedServer_SubImage

Kuyini lokho kwabasebenzisi neseva yewebhu?

Ukuyichaza ngendlela emfushane nelula, iseva yewebhu (i-apache, i-nginx, noma yini) idinga ukuvula izinqubo ohlelweni, izinqubo ezizobe zizo ezithatha amafayela ku-HDD (izithombe, njll.) itholakala kusiphequluli seklayenti. Isiphakeli sewebhu asikwazi ukumane sithathe amafayela siwasebenzise njengabantu, okungukuthi, sidinga umsebenzisi ozoba nguye ozokwenza konke lokhu ekugcineni, futhi lowo msebenzisi nguyena engikhuluma ngaye, uyaqonda?

Yini leyo yokuhlukanisa kubasebenzisi abaningana?

Ake sicabange ukuthi kuseva yethu sinamawebhusayithi ama-2, awethu okungumsebenzi womuntu siqu, nenye enye (ake sicabange ukuthi yintombi yethu noma eyomfowethu). Noma sisebenzisa imininingwane ehlukile nabasebenzisi abahlukile ukufinyelela kuyo, ekugcineni amafayela wawo womabili amawebhusayithi asetshenziswa ngumsebenzisi ofanayo, ukucutshungulwa kwe-PHP kuphathwa ngumsebenzisi ofanayo kuwo wonke amasayithi (imvamisa kuba www-data). Lo mkhuba onganconyiwe, kungcono ukuthi konke kuhlukaniswe kahle, njengoba kusho isisho esidala, kungcono ukuthi uphephe kunokuzisola.

Ok ngiyaqonda ukuthi ngenza kanjani ngeNginx

2000px-Nginx_logo.svg

Into yokuqala okufanele uyiqaphele ukuthi i-Nginx ayinayo imodyuli yayo ephatha ukucubungulwa kwe-PHP njengoba kwenza i-Apache, kuNginx sidinga ukusebenzisa i-PHP-CGI noma i-PHP-FPM, esebenza kahle futhi (noma engcono) kune-Apache. Ngakho-ke ukuze sihlukanise ukucubungula kwe-PHP kubasebenzisi abahlukahlukene, kuzodingeka sishintshe imigqa kumafayili wokumiswa kwe-PHP (i-CGI noma i-FPM), hhayi i-Nginx uqobo.

Ake sithi usebenzisa I-PHP-FPM, Sizokwakha ifayela lokumiswa le- Ichibi kwesiza esithile, okungukuthi, ichibi liyindlela yokuhlukanisa ukucubungula kwe-PHP kusuka ku-PHP-FPM, kepha siya ezingxenyeni ezithile.

1. Okokuqala kufanele sazi ukuthi yimuphi umsebenzisi wohlelo esizolusebenzisa, ngizocabanga ukuthi namanje asikakutholi okwenziwe kahle, ake sikudale:

Yonke imiyalo elandelayo KUFANELE yenziwe ngamalungelo okuphatha, kungaba ngezimpande eziqondile noma ngokusebenzisa iSudo

adduser blog

Sizoqala inqubo ejwayelekile yokwakha umsebenzisi, faka iphasiwedi, njll.

Ngibhuloga umsebenzisi ukulandela nje isibonelo, ukuthi isiza sokuqala esizosibamba kuzoba yi-blog, kuhle ukuthi ... ukwazi umsebenzisi ngamunye onesayithi elihlobene naye

1. Okokuqala ake siye ku /etc/php5/fpm/pool.d/:

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

2. Manje, sizokwakha ifayela elibizwa ngeblog.conf:

touch blog.conf

3. Manje sizobeka ukumiswa kwechibi esizolisebenzisela i-VHost blog:

Hlela ifayela le-blog.conf nge-nano ... ngokwesibonelo: I-sudo nano blog.conf
[blog] umsebenzisi = blog
iqembu = blog
lalela = / var / run / php5-fpm-blog.lalela lalela umnikazi = blog
lalela iqembu = blog
pm = ondemand pm.max_children = 96 chdir = /

Nota: Lokho engikumaka ngokubomvu yilokho okufanele bakushintshe ngokuya ngomsebenzisi abebemdala ngaphambili. Isibonelo, uma benza enye i-VHost ngomunye umsebenzisi (iforamu ngokwesibonelo) bese esikhundleni sebhulogi umane ubeke isithangami kulayini ngamunye, ngabe kuyaqondakala?

4. Lapho ukucushwa kwechibi elisha (ifayela le-blog.conf esisanda kulidala futhi salihlela), kuyithuba lokutshela i-Nginx VHost ukuthi isebenzise i-sock ehlukile yaleyo VHost, yaleli sayithi. Isokisi elizosetshenziswa kuzoba yilelo esalimemezela ngaphambilini (/var/run/php5-fpm-blog.sock). Ake sihlele i-Nginx VHost nasengxenyeni yokucubungula ye-PHP, sikhombisa ukusebenzisa lawo masokisi. Ngokwesibonelo:

indawo ~ \ .php $ {uma (! -f $ request_filename) {buyela 404; }
i-fastcgi_pass unix: / var / run / php5-fpm-blog.bheka;
faka ama-fastcgi_params; i-fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name; i-fastcgi_read_timeout 300; }

Njengoba ukwazi ukubona, ngikhombisa ukuthi ukucubungula kwe-PHP kwaleyo VHost (leyo migqa eyisibonelo ngaphakathi / njll / nginx / amasayithi anikwe amandla / i-vhost-blog) kwenze ngamasokisi atholakala ku- /var/run/php5-fpm-blog.sock ... okuyiwona esidale phambilini lapho sihlela /etc/php5/fpm/pool.d/blog.conf ...?

5. Uma lokhu sekwenziwe, siqala kabusha zombili izinsiza (php5-fpm ne-nginx) ne-voila, sizobona ukuthi ukucutshungulwa kwaleyo sayithi (vhost) AKWENZIWA nge-www-data noma impande noma omunye ofanayo, kodwa ngumsebenzisi kuchazwe ngaphambilini.

Lapha ngikukhombisa umphumela wefayela le- ps noma | gp fpm kwelinye lamaseva we-node yami:

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

Njengoba ukwazi ukubona ... ukwahlukanisa ukucubungula kwe-PHP ngabasebenzisi abasebenzisa i-Nginx + PHP-FPM kulula impela, lapho uyabona ukuthi kunamachibi amaningi, njengoba kukhona abasebenzisi abaningana.

Iziphetho

Uma kukhulunywa ngamaseva, awusoze waba neparanoid ngokwanele ... ukuphepha akuyona into yokudlala nayo, lapho sizama njalo ukwenza ngcono ukuphepha kwamaseva ethu nezinsizakalo zawo, mancane amathuba okuthi sizokwesaba (ngempumelelo) umzamo wokugenca noma yini efanayo 😉


Okuqukethwe yi-athikili kunamathela ezimisweni zethu ze izimiso zokuhlelela. Ukubika iphutha chofoza lapha.

Amazwana ayi-9, shiya okwakho

Shiya umbono wakho

Ikheli lakho le ngeke ishicilelwe. Ezidingekayo ibhalwe nge *

*

*

  1. Ubhekele imininingwane: Miguel Ángel Gatón
  2. Inhloso yedatha: Lawula Ugaxekile, ukuphathwa kwamazwana.
  3. Ukusemthethweni: Imvume yakho
  4. Ukuxhumana kwemininingwane: Imininingwane ngeke idluliselwe kubantu besithathu ngaphandle kwesibopho esisemthethweni.
  5. Isitoreji sedatha: Idatabase ebanjwe yi-Occentus Networks (EU)
  6. Amalungelo: Nganoma yisiphi isikhathi ungakhawulela, uthole futhi ususe imininingwane yakho.

  1.   isihlibhi kusho

    Gaara, ezikhathini zamanje lezi zinto kufanele zenziwe ngendlela ezenzakalelayo ngangokunokwenzeka, ngincoma ukuthi uzame i-Ansible. Ngaphandle kwe-ejenti, udinga kuphela i-python kusikhungo esikude, esilula kakhulu ukumisa, amafayela we-yaml, izifanekiso zeJinja.

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

    1.    KZKG ^ Gaara kusho

      Ake sibheke, lokho akuhlali kungokwamasayithi e-WordPress kuphela, futhi ... haha ​​mhlawumbe i-Ansola ichofozwa kalula, kepha ngincamela ukwazi kahle ukuthi konke kusebenza kanjani kuseva, noma ngabe kufanele ngichithe iminithi elingu-1 ngakha amasokisi amasha futhi i-VHost entsha 😀

      1.    isihlibhi kusho

        Nge-Ansible wenza konke okuzenzakalelayo, wenza cishe noma yini oyifunayo, inzuzo yale ndlela ukuthi uhlanganisa umkhuba bese wenza ngokuthanda, cabanga ukuthi unesayithi elilayishwe kakhulu futhi ufuna ukulayisha ukulinganisa phakathi kwamaseva wohlelo lokusebenza, lezi kufanele ilungiselelwe ngokufana ncamashi awukwazi ukweqa isinyathelo noma wenze okuhlukile kwesinye sazo, ungacabanga yini ukwenza inqubo igxathu negxathu? Nge-Ansible kulula njengokungeza igama lomethuleli kufayela lokusungula kanye neVoilá !!

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

      2.    isihlibhi kusho

        Uxolo ngenkolo eyi-Ansible, kepha ingenye yalezi zinhlobo zobuchwepheshe obutholayo futhi ufuna ukuthi bonke abantu bazisebenzise manje ngoba zipholile futhi ziyasebenza, kufana nokuthi uma uthola i-NGINX futhi ufuna bonke abangane bakho bashiye i-Apache ngokushesha.

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

  2.   I-Mstaaravin kusho

    Ngiyaqiniseka ukuthi okuthunyelwe kwami ​​kukugcwalisa lokhu ...
    http://blog.ngen.com.ar/configuracion-segura-de-un-webserver-con-nginx-php-fpm/

  3.   Ukubola87 kusho

    Ngingunjiniyela (noma ngifundela ukuba) umqambi futhi nge-NGIX ngibe nezinkinga eziningi lapho ngilungiselela i-nginx + php-fpm. Ngiyazi ukuthi i-archlinux distro akuyona engcono yokwenza njengeseva, kepha ngaso sonke isikhathi lapho ngivuselela inguqulo ye-ngix noma i-php yonke into ihlale iphahlazeka ngakho-ke ngiyeka ukuzama lol ... Okwanamuhla ngihlala ne-Apache + yakudala I-PHP kepha ngizobona uma ngiphinda ngijikeleza i-NGIX ... mhlawumbe kumshini obonakalayo

    1.    isihlibhi kusho

      Isimo sengqondo sishintsha kancane, i-nginx isebenza kokuqukethwe okumile futhi isebenza njengommeleli obuyela emuva we-php-fpm okunguye osebenzisa i-PHP yangempela, kufanele uqale ezingxenyeni ezithile uphinde ufeze isinyathelo sokuhambisa ngesinyathelo, funa umhlahlandlela wokuphaka uhlaka osebenza ngalo, ngamunye unemininingwane yawo ngamagama omphakathi, i-static, izinsiza kusebenza, njll.

  4.   engaziwa kusho

    Ingabe umphakathi wenza umusa omkhulu wokushiya igama elithi "hostear", elingekho. NguNkulunkulu, ingabe kunzima kangaka ukuthi "umphathi"?

  5.   U-Wil kusho

    Sanibonani, ukulandela isibonelo senu ngithanda ukwazi ukuthi ngabe ichibi lingenziwa kuphela i-wordpress backen, okungukuthi, nge-wp-admin eyenza isokhethi elisha lokuxhumeka okungenayo ku-backend

    indawo / wp-admin {
    impande /var/www/yoursite.com/wp-admin;
    index index.php index.html index.htm;
    indawo ~ ^ / wp-admin /(.+. php) $ {
    zama_files $ uri = 404;
    impande /var/www/yoursite.com/wp-admin;
    faka / / etc / nginx / fastcgi_paramu;

    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/;
    }
    }