¶à°æ±¾¹²´æ£ºCentOSÉÏͬʱ´î½¨¶à¸öwebЧÀÍÆ÷µÄÖ¸ÄÏ
¶à°æ±¾¹²´æ£ºCentOSÉÏͬʱ´î½¨¶à¸öwebЧÀÍÆ÷µÄÖ¸ÄÏ
ÔÚÏÖ´úµÄweb¿ª·¢ÖУ¬¾³£ÐèÒªÔÚͳһ̨ЧÀÍÆ÷Éϴ¶à¸öwebЧÀÍÆ÷£¬ÒÔÖª×ã²î±ðÏîÄ¿»ò²î±ð°æ±¾µÄÐèÇó¡£±¾ÎĽ«Ö¸µ¼ÄúÔõÑùÔÚCentOS²Ù×÷ϵͳÉÏʵÏÖ¶à°æ±¾webЧÀÍÆ÷µÄͬʱ´î½¨¡£
Ê×ÏÈ£¬ÎÒÃÇÐèҪװÖúÍÉèÖÃApacheºÍNginxÁ½¸öÖ÷Á÷µÄwebЧÀÍÆ÷¡£ÒÔÏÂÊÇÔÚCentOSÉÏ×°ÖÃApacheºÍNginxµÄ°ì·¨£º
×°ÖÃApache
ʹÓÃÒÔÏÂÏÂÁî×°ÖÃApache£º
sudo yum install httpd
µÇ¼ºó¸´ÖÆ
×°ÖÃÍê³Éºó£¬Æô¶¯Apache²¢½«ÆäÉèÖÃΪ¿ª»ú×ÔÆô¶¯£º
sudo systemctl start httpd sudo systemctl enable httpd
µÇ¼ºó¸´ÖÆ
×°ÖÃNginx
ʹÓÃÒÔÏÂÏÂÁî×°ÖÃNginx£º
sudo yum install nginx
µÇ¼ºó¸´ÖÆ
×°ÖÃÍê³Éºó£¬Í¬ÑùÆô¶¯Nginx²¢ÉèÖÃΪ¿ª»ú×ÔÆô¶¯£º
sudo systemctl start nginx sudo systemctl enable nginx
µÇ¼ºó¸´ÖÆ
ÖÁ´Ë£¬ÎÒÃÇÒÑÍê³ÉÁËApacheºÍNginxµÄ×°ÖúÍÉèÖ᣽ÓÏÂÀ´£¬ÎÒÃǽ«ÉèÖöà¸ö°æ±¾µÄwebЧÀÍÆ÷¡£
ÉèÖÃApacheµÄ¶à°æ±¾
Ê×ÏÈ£¬ÎÒÃÇÐèҪΪÿ¸ö²î±ð°æ±¾µÄwebЧÀÍÆ÷½¨Éè²î±ðµÄÐéÄâÖ÷»ú¡£ÔÚApacheÖУ¬ÐéÄâÖ÷»úµÄÉèÖÃÎļþλÓÚ/etc/httpd/conf.dĿ¼Ï¡£ÎÒÃÇ¿ÉÒÔΪÿ¸ö°æ±¾½¨ÉèÒ»¸öÏìÓ¦µÄÉèÖÃÎļþ£¬ÀýÈ磬ÎÒÃǽ¨ÉèÁ½¸ö°æ±¾µÄÐéÄâÖ÷»ú£¬»®·ÖÊÇvhost1.confºÍvhost2.conf¡£
½¨Éèvhost1.conf£º
sudo vi /etc/httpd/conf.d/vhost1.conf
µÇ¼ºó¸´ÖÆ
½«ÒÔÏÂÄÚÈÝÌí¼Óµ½vhost1.confÎļþÖУº
<VirtualHost *:80> ServerAdmin admin@vhost1.com DocumentRoot /var/www/vhost1 ServerName vhost1.com <Directory /var/www/vhost1> AllowOverride All Require all granted </Directory> </VirtualHost>
µÇ¼ºó¸´ÖÆ
½¨Éèvhost2.conf£º
sudo vi /etc/httpd/conf.d/vhost2.conf
µÇ¼ºó¸´ÖÆ
½«ÒÔÏÂÄÚÈÝÌí¼Óµ½vhost2.confÎļþÖУº
<VirtualHost *:80> ServerAdmin admin@vhost2.com DocumentRoot /var/www/vhost2 ServerName vhost2.com <Directory /var/www/vhost2> AllowOverride All Require all granted </Directory> </VirtualHost>
µÇ¼ºó¸´ÖÆ
ÉúÑIJ¢Í˳öÉèÖÃÎļþ¡£½ÓÏÂÀ´£¬ÎÒÃÇÐèÒª½¨ÉèÏìÓ¦µÄÍøվĿ¼²¢ÉèÖÃȨÏÞ£º
sudo mkdir /var/www/vhost1 sudo chmod -R 755 /var/www/vhost1 sudo mkdir /var/www/vhost2 sudo chmod -R 755 /var/www/vhost2
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
ÖØÆôApacheʹÉèÖÃÉúЧ£º
sudo systemctl restart httpd
µÇ¼ºó¸´ÖÆ
ÉèÖÃNginxµÄ¶à°æ±¾
ͬÑù£¬ÔÚNginxÖУ¬ÎÒÃÇÒ²ÐèҪΪÿ¸ö°æ±¾½¨Éè²î±ðµÄÉèÖÃÎļþ¡£NginxµÄÉèÖÃÎļþλÓÚ/etc/nginx/conf.dĿ¼Ï¡£
½¨Éèvhost1.conf£º
sudo vi /etc/nginx/conf.d/vhost1.conf
µÇ¼ºó¸´ÖÆ
½«ÒÔÏÂÄÚÈÝÌí¼Óµ½vhost1.confÎļþÖУº
server { listen 80; server_name vhost1.com; root /var/www/vhost1; index index.html index.htm; location / { try_files $uri $uri/ =404; } }
µÇ¼ºó¸´ÖÆ
½¨Éèvhost2.conf£º
sudo vi /etc/nginx/conf.d/vhost2.conf
µÇ¼ºó¸´ÖÆ
½«ÒÔÏÂÄÚÈÝÌí¼Óµ½vhost2.confÎļþÖУº
server { listen 80; server_name vhost2.com; root /var/www/vhost2; index index.html index.htm; location / { try_files $uri $uri/ =404; } }
µÇ¼ºó¸´ÖÆ
ÉúÑIJ¢Í˳öÉèÖÃÎļþ¡£½ÓÏÂÀ´£¬ÎÒÃÇÐèÒª½¨ÉèÏìÓ¦µÄÍøվĿ¼²¢ÉèÖÃȨÏÞ£º
sudo mkdir /var/www/vhost1 sudo chmod -R 755 /var/www/vhost1 sudo mkdir /var/www/vhost2 sudo chmod -R 755 /var/www/vhost2
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
ÖØÆôNginxʹÉèÖÃÉúЧ£º
sudo systemctl restart nginx
µÇ¼ºó¸´ÖÆ
ÖÁ´Ë£¬ÎÒÃÇÒÑÀÖ³ÉÉèÖÃÁËApacheºÍNginxµÄ¶à°æ±¾webЧÀÍÆ÷¡£Äú¿ÉÒÔƾ֤ÐèÒªÌí¼Ó¸ü¶àµÄÐéÄâÖ÷»úºÍÉèÖÃÎļþ¡£
×ܽ᣺
±¾ÎÄÏÈÈÝÁËÔõÑùÔÚCentOS²Ù×÷ϵͳÉÏ×°ÖúÍÉèÖÃApacheºÍNginx£¬²¢Í¨¹ý½¨ÉèÐéÄâÖ÷»úºÍÉèÖÃÎļþʵÏÖ¶à°æ±¾webЧÀÍÆ÷µÄͬʱ´î½¨¡£Ê¹Óöà°æ±¾webЧÀÍÆ÷£¬Äú¿ÉÒÔÀû±ãµØÖª×ã²î±ðÏîÄ¿»ò²î±ð°æ±¾µÄÐèÇó¡£×£ÄúÔÚweb¿ª·¢ÖÐÈ¡µÃÀֳɣ¡
ÒÔÉϾÍÊǶà°æ±¾¹²´æ£ºCentOSÉÏͬʱ´î½¨¶à¸öwebЧÀÍÆ÷µÄÖ¸ÄϵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡