自己的vps上放了別人的網站,那怎么樣讓自己的網站和別人的網站能同時被訪問呢?需要使用apache的虛擬主機配置。
配置httpd.conf文件
比如原來是這種只是指向一個目錄的配置
DocumentRoot "/opt/lampp/htdocs/ppe112" <Directory "/opt/lampp/htdocs/ppe112"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/trunk/mod/core.html#options # for more information. # #Options Indexes FollowSymLinks # XAMPP Options Indexes FollowSymLinks ExecCGI Includes # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # #AllowOverride None # since XAMPP 1.4: AllowOverride All # # Controls who can get stuff from this server. # Require all granted </Directory>
把這段話變成
<VirtualHost 198.199.107.XXX> #這里填主機的ip地址 ServerName www.AAA.com DocumentRoot "/opt/lampp/htdocs/AAA" <Directory "/opt/lampp/htdocs/AAA"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/trunk/mod/core.html#options # for more information. # #Options Indexes FollowSymLinks # XAMPP Options Indexes FollowSymLinks ExecCGI Includes # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # #AllowOverride None # since XAMPP 1.4: AllowOverride All # # Controls who can get stuff from this server. # Require all granted </Directory> </VirtualHost> <VirtualHost 198.199.107.XXX> #這里填主機的ip地址 ServerName www.BBB.com DocumentRoot "/opt/lampp/htdocs/BBB" <Directory "/opt/lampp/htdocs/BBB"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/trunk/mod/core.html#options # for more information. # #Options Indexes FollowSymLinks # XAMPP Options Indexes FollowSymLinks ExecCGI Includes # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # #AllowOverride None # since XAMPP 1.4: AllowOverride All # # Controls who can get stuff from this server. # Require all granted </Directory> </VirtualHost>
這樣就實現了AAA網站和BBB網站同時在服務器上共存,外部兩個域名指向同一個ip,內部解析到不同服務器目錄的操作。
PS:這里這里只能正常訪問www.AAA.com www.BBB.com這兩個,如果要直接訪問AAA.com BBB.com 也需要如上再配置一遍。