Host ntau VHosts nrog cov neeg siv sib txawv hauv Nginx

Qhov teeb meem feem ntau hauv lub ntiaj teb thaum koj muaj lub server, yog xav txog kev ruaj ntseg thiab muaj kev nyab xeeb ntxiv, koj yeej tsis tuaj yeem yog qhov tsis txaus ntseeg

Ib qho kev coj ua uas ib txwm muaj thiab TSIS tau hais qhia pom zoo, yog siv tib tus neeg siv rau txhua lub databases, zuj zus yog tias siv hauv paus, uas tsis txaus ntseeg li nws yuav zoo li, muaj cov uas (vim vagrancy los sis tsis quav ntsej) ua qhov no, Kuv twb tham txog vim li cas koj yuav TSIS ua zoo li no rau hauv lwm tus ncejTam sim no nws yog lub sijhawm los piav qhia txog yuav ua li cas thiab vim li cas nws yog qhov zoo dua los cais lub web server ua rau hauv cov neeg siv sib txawv, lub sijhawm no nws yuav siv Nginx.

DedicatedServer_SubImage

Dab tsi yog tias cov neeg siv thiab lub web server?

Txhawm rau piav qhia nws hauv txoj kev luv luv thiab yooj yim, lub web server (apache, nginx, xijpeem) yuav tsum tau qhib cov txheej txheem hauv qhov system, cov txheej txheem uas yuav yog cov uas nqa cov ntaub ntawv los ntawm HDD (cov duab, thiab lwm yam) thiab ua rau lawv muaj rau tus neeg siv lub browser. Lub web server tsis tuaj yeem nqa cov ntaub ntawv thiab tswj lawv tsis yog leej twg, ntawd yog, nws xav tau tus neeg siv uas yuav yog tus uas yuav ua txhua yam no thaum kawg, thiab tus neeg siv ntawd yog tus uas kuv hais txog, koj puas nkag siab?

Dab tsi yog hais tias kev sib cais hauv ob peb tus neeg siv?

Piv txwv tias peb muaj 2 lub vev xaib ntawm peb lub server, peb tus kheej yog tus kheej qhov project, thiab lwm tus (wb xav tias nws yog peb tus hluas nkauj lossis tus nus kwv tij)). Txawm tias thaum peb siv cov ntaub ntawv sib cais thiab cov neeg siv sib txawv los nkag rau lawv, thaum kawg cov ntaub ntawv ntawm ob lub vev xaib raug tswj los ntawm tib tus siv, kev ua haujlwm PHP yog tswj los ntawm tib tus siv rau txhua qhov chaw (nws feem ntau yog www-data)). Nov yog qhov kev xyaum uas tsis yog kev pom zoo, nws yog qhov zoo dua kom muaj txhua yam zoo sib cais, raws li cov lus qub hais tseg, nws zoo dua yog kev nyab xeeb dua li thov txim.

Ok Kuv nkag siab, yuav ua li cas kuv ua nrog Nginx

2000px-Nginx_logo.svg

Thawj qhov yuav tsum ceeb toom yog tias Nginx tsis muaj nws tus qauv uas tuav PHP ua raws li Apache ua, rau Nginx peb yuav tsum siv PHP-CGI lossis PHP-FPM, uas ua haujlwm zoo ib yam nkaus (lossis zoo dua) dua Apache. Yog li txhawm rau cais ua PHP hla cov neeg siv sib txawv, peb yuav tau hloov kab hauv PHP configuration files (CGI lossis FPM), tsis yog Nginx nws tus kheej.

Xws li koj siv PHP-FPM, peb yuav tsim cov ntaub ntawv teeb tsa ntawm pas dej ua ke Rau cov xaib tshwj xeeb, uas yog, pas dej ua ke yog txoj kev los cais cov txheej txheem PHP los ntawm PHP-FPM, tab sis peb mus hauv seem.

1. Ua ntej peb yuav tsum paub tus neeg siv ntawm lub system peb yuav siv, Kuv yuav xav tias peb tseem tsis tau muaj tsim thiab zoo, cia peb tsim nws:

Tag nrho cov lus txib hauv qab no YUAV TSUM tau nrog txoj cai tswj hwm, nrog rau lub hauv paus ncaj qha lossis siv sudo

adduser blog

Peb yuav pib cov txheej txheem ib txwm ntawm kev tsim ib tus neeg siv, sau tus password, thiab lwm yam.

Kuv blog tus neeg siv tsuas yog ua raws li tus piv txwv, tias thawj lub vev xaib uas peb yuav tuav yuav yog blog, zoo tias ... kom paub txhua tus neeg siv nrog lub vev xaib ntawd cuam tshuam dab tsi

1. Xub thawj mus rau /etc/php5/fpm/pool.d/:

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

2. Tam sim no, peb yuav tsim ib daim ntawv hu ua blog.conf:

touch blog.conf

3. Tam sim no peb yuav tso qhov kev teeb tsa ntawm lub pas dej uas peb yuav siv rau VHost blog:

Kho kom raug cov ntaub ntawv blog.conf nrog nano ... piv txwv: sudo nano blog.conf
[blog] neeg siv = blog
pawg = blog
mloog = / var / khiav / php5-fpm-blog.sock mloog.qhov muag = blog
mloog.group = blog
pm = ondemand pm.max_children = 96 chdir = /

Ceeb toom: Qhov kuv kos lawv ua xim liab yog qhov lawv yuav tsum hloov kho nyob ntawm tus neeg siv uas lawv tau tsim dhau los. Piv txwv, yog tias lawv tsim lwm VHost nrog lwm tus siv (kev sab laj piv txwv) tom qab ntawd es tsis yog blog tsuas yog muab cov rooj sib tham hauv txhua kab, puas yog to taub?

4. Thaum lub teeb tsa ntawm lub pas dej tshiab (blog.conf ntawv uas peb nyuam qhuav tsim thiab kho), nws yog qhov tig tau los qhia rau Nginx VHost kom siv lub thom khwm sib txawv rau VHost, rau lub xaib no. Cov thom khwm uas yuav siv yuav yog qhov peb tau tshaj tawm yav dhau los (/var/run/php5-fpm-blog.sock). Cia peb hloov lub Nginx VHost thiab hauv PHP ua ntu, peb qhia tias siv lub thom khwm no. Piv txwv li:

qhov chaw ~ \ .php $ {yog (! -f $ thov_filename) {rov qab 404; }
fastcgi_pass unix: / var / khiav / php5-fpm-blog.coj;
suav nrog fastcgi_params; fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name; fastcgi_read_timeout 300; }

Raws li koj tuaj yeem pom, kuv qhia tias PHP ua tiav ntawm VHost (cov kab ntawd yog piv txwv rau sab hauv / etc / nginx / sites-enabled / vhost-blog) ua nws nrog cov thom khwm pom nyob rau hauv /var/run/php5-fpm-blog.sock ... uas yog qhov peb tau tsim yav tas los thaum kho /etc/php5/fpm/pool.d/blog.conf ... yog nws to taub tsis yog?

5. Thaum qhov no ua tiav, peb rov qab ob qho kev pabcuam (php5-fpm thiab nginx) thiab voila, peb yuav pom tias kev ua ntawm lub xaib ntawd (vhost) tsis ua tiav los ntawm www-cov ntaub ntawv lossis lub hauv paus lossis ib tus neeg zoo sib xws, tab sis los ntawm tus neeg siv uas peb yav tas los txhais.

Ntawm no kuv qhia koj qhov tawm ntawm a ps aw | pib fp ntawm ib qho ntawm kuv cov servers:

ps aux | grep fpm ebook 586 0.0 0.0 349360 1204? S Mar30 0:00 php-fpm: pas dej ebook ebook 589 0.0 0.0 349360 1204? S Mar30 0:00 php-fpm: pas dej ebook www 608 0.0 0.2 350084 5008? S Mar30 0:00 php-fpm: pas dej www www 609 0.0 0.2 350600 5048 30? S Mar0 00:3 php-fpm: pas dej www tv611 0.0 0.0 349360 1204 30? S Mar0 00:3 php-fpm: pas dej tv3 tv615 0.0 0.0 349360 1204 30? S Mar0 00:3 php-fpm: pas dej tv1818 tshooj 1.7 1.7 437576 36396 09? S 55:0 46:2264 php-fpm: pas dej vwj luam ntawv xov xwm 1.9 1.7 437332 35884 10? S 15:0 26:2338 php-fpm: pas dej magazine me nyuam 4.3 1.0 428992 22196 10? S 18:0 53:2413 php-fpm: pas dej xov tooj cua 1.8 1.7 437764 36152 10? S 22:0 18:2754 php-fpm: pas dej lwg tshooj 3.5 1.3 356724 27164 10? S 38:0 00:5624 php-fpm: pas dej num gutl cgr 0.0 1.0 365168 22696 28? S Apr0 16:7900 php-fpm: pas dej cgr menyuam 0.3 2.5 457052 52444 25? S Apr20 23:11021 php-fpm: pas dej rov muaj tub kawm ntawv 0.4 2.5 458316 52864 28? S Apr5 57:11254 php-fpm: pas dej sig ncaug cgr 0.0 1.0 363152 21708 28? S Apr0 12:13184 php-fpm: pas dej cgr cgr 0.0 1.0 362872 21360 28? S Apr0 08:XNUMX php-fpm: pas dej cgr

Raws li koj tuaj yeem pom ... cais cov txheej txheem PHP ua los ntawm cov neeg siv Nginx + PHP-FPM yog qhov yooj yim heev, nyob ntawd koj pom tias muaj ob peb pas dej ua ke, raws li muaj ob peb cov neeg siv.

SIB THAM

Thaum nws los txog rau servers, koj yeej tsis yog qhov zoo tshaj plaws ... kev nyab xeeb tsis yog ib yam dab tsi los ua si nrog, qhov ntau peb ib txwm sim los txhim kho kev nyab xeeb ntawm peb cov servers thiab lawv cov kev pabcuam, qhov tsawg dua peb yuav ntshai los ntawm (vam meej) hack sim lossis txhua yam zoo sib xws


Cov ntsiab lus ntawm tsab xov xwm ua raws li peb cov ntsiab cai ntawm kev tswj hwm kev ncaj nceesCov. Tshaj tawm ib qho yuam kev nyem no.

9 lus, tawm koj li

Tso koj saib

Koj email chaw nyob yuav tsis tsum luam tawm. Yuav tsum tau teb cov cim nrog *

*

*

  1. Lub luag haujlwm rau cov ntaub ntawv: Miguel Ángel Gatón
  2. Lub hom phiaj ntawm cov ntaub ntawv: Tswj SPAM, kev tswj xyuas tawm tswv yim.
  3. Sau raws cai: Koj kev tso cai
  4. Kev sib txuas lus ntawm cov ntaub ntawv: Cov ntaub ntawv yuav tsis raug xa mus rau lwm tus neeg thib peb tsuas yog los ntawm kev txiav txim siab raug cai.
  5. Cov ntaub ntawv khaws cia: Cov Ntaub Ntawv khaws tseg los ntawm Occentus Networks (EU)
  6. Txoj Cai: Txhua lub sijhawm koj tuaj yeem txwv, rov qab thiab tshem tawm koj cov ntaub ntawv.

  1.   dhunter said

    Tam sim no, nyob rau lub sijhawm tam sim no cov khoom no yuav tsum tau muab suab kom ntau li ntau tau, Kuv xav kom koj sim teb. Tsis muaj tus neeg sawv cev, koj tsuas xav tau sej ntawm tus tswv tsev tuaj deb, yooj yim rau kev teeb tsa, cov ntaub ntawv yaml, Jinja cov qauv.

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

    1.    KZKG ^ Gaara said

      Cia peb pom, uas tsis yog ib txwm muaj rau WordPress cov chaw, thiab ... haha ​​tej zaum qhov lus hnov ​​volao, tab sis kuv nyiam paub meej raws nraim txhua yam ua haujlwm ntawm lub server li cas, txawm tias kuv yuav tsum siv sijhawm 1 feeb tsim lub thom khwm tshiab thiab tshiab VHost 😀

      1.    dhunter said

        Nrog Ansible koj automate txhua yam, koj ua txhua yam uas koj xav tau, qhov zoo ntawm hom no yog koj encapsulate kev coj ua thiab tom qab ntawd ua tiav ntawm yuav, xav txog tias koj muaj qhov chaw thau khoom hnyav thiab koj xav ua kom sib npaug ntawm daim ntawv thov servers, cov no yuav tsum tau teeb tsa qhov qub zoo ib yam koj tsis tuaj yeem hla ib qib lossis ua ib yam dab tsi sib txawv hauv ib qho ntawm lawv, koj puas tuaj yeem xav ua txoj kev ua tus txheej txheem ib kauj ruam 4 zaug? Nrog Cov Lus Teb nws yooj yim xws li ntxiv cov hostname rau cov ntawv pov thawj khoom thiab Voilá !!

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

      2.    dhunter said

        Thov txim ntawm Ansible cult, tab sis nws yog ib qho ntawm cov thev naus laus zis uas koj pom thiab koj xav kom txhua tus siv tam sim no vim tias nws tau txias thiab siv tau, nws zoo li thaum koj pom NGINX thiab koj xav kom tag nrho koj cov phooj ywg tawm hauv Apache tam sim.

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

  2.   Mstaaravin said

    Kuv ntseeg tau tias kuv cov post ua tiav qhov no ...
    http://blog.ngen.com.ar/configuracion-segura-de-un-webserver-con-nginx-php-fpm/

  3.   Roob 87 said

    Kuv (lossis kawm los ua) tus tsim tawm thiab nrog NGIX Kuv muaj teebmeem ntau thaum tsim kho nginx + php-fpm. Kuv paub tias archlinux distro tsis yog qhov zoo tshaj plaws los ua nws ua tus neeg rau zaub mov, tab sis txhua zaus kuv tau kho dua tshiab version ntawm ngix lossis php txhua yam poob ib txwm yog li kuv tau tso lub dag zog lol ... Rau hnub no kuv nyob nrog lub Apache qub + PHP tab sis kuv yuav pom tias kuv mus ncig NGIX dua ... tej zaum hauv lub tshuab virtual

    1.    dhunter said

      Lub siab lub ntsws pauv hloov me ntsis, nginx ua haujlwm pabcuam cov ntsiab lus zoo li qub thiab ua haujlwm pabcuam thim rov qab rau php-fpm uas yog tus sau PHP tiag, koj yuav tsum pib ua ntu thiab ua tiav lub kauj ruam los ntawm kauj ruam, saib cov lus qhia coj mus siv lub moj khaum koj ua haujlwm nrog, txhua tus nws muaj nws cov ntsiab lus los ntawm cov npe ntawm pej xeem, zoo li qub, peev txheej, thiab lwm yam ...

  4.   anonymous said

    Ua rau lub zej zog muaj kev pom zoo zoo ntawm kev tso cov lus "hostear", uas tsis muaj nyob. Los ntawm Vajtswv, nws puas yog qhov nyuaj hais “host”?

  5.   Wil said

    Kev txais tos, ua raws li koj tus piv txwv Kuv xav paub yog tias lub pas dej tuaj yeem tsim tau rau wordpress rov qab, uas yog, rau wp-admin ua qhov tshiab rau kev nkag mus txuas rau rov qab

    qhov chaw / wp-admin {
    cag /var/www/yoursite.com/wp-admin;
    Performance index.php index.html index.htm;
    qhov chaw ~ ^ / wp-admin /(.+. php) $ {
    try_files $ uri = 404;
    cag /var/www/yoursite.com/wp-admin;
    xws li / etc / 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/;
    }
    }