LAMP-Apache虛擬機器主機

來源:互聯網
上載者:User

標籤:虛擬機器主機

    在一個Apache伺服器上可以配置多個虛擬機器主機,實現一個伺服器提供多網站服務,其實就是訪問同一個伺服器上的不同目錄。Apache虛擬機器主機配置有3中方法:基於IP配置、基於網域名稱配置和基於連接埠配置。下面將示範基於網域名稱的虛擬機器主機。

1、編輯httpd.conf

[[email protected] ~]# vi /usr/local/apache2.4/conf/httpd.confInclude conf/extra/httpd-vhosts.conf    ##啟用httpd-vhosts.conf

2、編輯httpd-vhosts.conf

[[email protected] ~]# vi /usr/local/apache2.4/conf/extra/httpd-vhosts.conf<VirtualHost *:80>                      ##預設虛擬機器主機    DocumentRoot "/data/www/abc.com"    ##網站根目錄    ServerName abc.com                  ##主網域名稱    ServerAlias  abc.net     ##網域名稱別名     ErrorLog "logs/abc.com-error_log"            ##錯誤記錄檔    CustomLog "logs/abc.com-access_log" common   ##訪問日誌</VirtualHost><VirtualHost *:80>    DocumentRoot "/data/www/123.com"    ServerName 123.com    ErrorLog "logs/123.com-error_log"    CustomLog "logs/123.com-access_log" common</VirtualHost>

3、建立網站目錄與檔案

[[email protected] ~]# mkdir /data/www[[email protected] ~]# mkdir /data/www/abc.com[[email protected] ~]# mkdir /data/www/123.com[[email protected] ~]# cat /data/www/abc.com/index.php<?phpecho "abc.com";?>[[email protected] ~]# cat /data/www/123.com/index.php<?phpecho "123.com";?>[[email protected] ~]# chmod 755 /data/www/123.com/index.php[[email protected] ~]# chmod 755 /data/www/abc.com/index.php

4、重新載入配置

[[email protected] ~]# /usr/local/apache2.4/bin/apachectl -tSyntax OK[[email protected] ~]# /usr/local/apache2.4/bin/apachectl graceful

5、測試虛擬機器主機效果

[[email protected] ~]# curl -x192.168.137.100:80 123.com<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>403 Forbidden</title></head><body><h1>Forbidden</h1><p>You don‘t have permission to access /on this server.<br /></p></body></html>

測試發現沒有許可權,由於前面給index.php檔案授權過,因此定位問題在httpd.conf。

[[email protected] ~]# vi /usr/local/apache2.4/conf/httpd.conf<Directory />    AllowOverride none#   Require all denied          ##將該行注釋掉</Directory>[[email protected] ~]# /usr/local/apache2.4/bin/apachectl graceful ##重新載入配置[[email protected] ~]# curl -x192.168.137.100:80 123.com123.com[[email protected] ~]# curl -x192.168.137.100:80 abc.com      abc.com[[email protected] ~]# curl -x192.168.137.100:80   ##匹配別名主機 abc.com[[email protected] ~]# curl -x192.168.137.100:80 abcd.com   ##採用預設虛擬機器主機abc.com


本文出自 “A man & A computer” 部落格,請務必保留此出處http://juispan.blog.51cto.com/943137/1951872

LAMP-Apache虛擬機器主機

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.