最新消息:觉得本站不错的话 记得收藏哦 博客内某些功能仅供测试 讨论群:135931704 快养不起小站了 各位有闲钱就打赏下把 My Email weicots#gmail.com Please replace # with @

win 下本地多域名解析+Apache多域名解析+Magento多域名解析一条龙

LINX ajiang-tuzi 4026浏览

Windows 下

本地域名解析操作步骤:

1.打开C:\WINDOWS\system32\drivers\etc目录

2.找到host文件,用记事本打开

3.添加“空间IP 域名”

如:本地添加 www.service3.com的域名解析

# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost
127.0.0.1           service1cn.com
127.0.0.1           service2en.com
127.0.0.1           service3.com

送两个小命令 win 下的

ipconfig /displaydns 查看DNS 缓存
ipconfig /flushdns   刷新DNS缓存

Apache 下

PHP&Apache配置多个域名解析的配置方法

apache是最流行的http服务器软件之一,其以快速、可靠(稳定)而著称,并且可通过简单的api扩展,perl/python解释器可被编译到服务器中,完全免费,并且源代码全部开放。如果有自己的服务器或者vps, 并且不想为了方便而购买昂贵的控制面板的话,那自己动手配置apache就成了一门必修课了。下面简单的介绍了如何通过设置apache的 http.conf文件,进行多个域名以及其相关的二级域名的绑定(假设我们要绑定的域名是weioct.com和weicot.com,二级域名是 service1.weicot.com,独立ip为127.0.0.1 举个栗子).

apache怎么绑定多个域名

打开http.conf

1,servername 127.0.0.1 修改成servername 127.0.0.1

2,#namevirtualhost * 修改成”namevirtualhost 127.0.0.1″

3,在文件最后面有虚拟主机格式,

#<virtualhost *>

#   serveradmin [email]admin@weicot.com[/email]

#   documentroot /www/httpd/html/weicot.com

#   servername www.weicot.com

#   errorlog logs/weicot.com-error_log

#   customlog logs/weicot.com-access_log common

#</virtualhost>

简单的添加:

<VirtualHost *:80>
    DocumentRoot "E:\XPP\htdocs\magento"
    ServerName service1cn.com 
    ServerAlias service1cn.com 
    ErrorLog logs/shop.com-error_log
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "E:\XPP\htdocs\magento"
    ServerName service2en.com
    ServerAlias service2en.com
    ErrorLog logs/shop.com-error_log
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin ajing-tuzi
    DocumentRoot "E:\XPP\htdocs\magento"
    ServerName service3.com
    ServerAlias service3.com
    ErrorLog logs/shop.com-error_log
</VirtualHost>
 

日志文件的话也可以按照自己的路径添加。
apache如何添加二级域名

httpd.conf 中需要打开mod_rewrite功能(关于url重定向的具体说明,可以参照.htaccess使用方法总结),具体操作就是,在httpd.conf 的最后,添加以下内容:

rewriteengine on

rewritemap lowercase int:tolower

rewritemap vhost txt:/usr/local/etc/apache/vhost.map

rewritecond ${lowercase:%{server_name}} ^(.+)$

rewritecond ${vhost:%1} ^(/.*)$

rewriterule ^/(.*)$ %1/$1

其中的 /usr/local/etc/apache 是你的 apache 服务器配置文件所在路径,根据实际情况更改(例如在/etc/httpd/下面)。然后,在这个所在路径的目录下创建一个文件: vhost.map,内容为:


service1.weicot.com /usr/local/www/service1.weicot.com

www.weicot.com /usr/local/www/weicot.com

service3.weicot.com /usr/local/www/weicot.com/service3

最后,在网站根目录 /usr/local/www/下,创建对应目录就可以了。如果需要增加,修改或者删除域名,子域名,仅仅需要更改vhost.map文件,而不用重启apache进程

Magento 下

//由于Magento 在这篇文章不是重点 所以我会开一贴单独讲 
<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    Mage
 * @package     Mage
 * @copyright  Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

if (version_compare(phpversion(), '5.3.0', '<')===true) {
    echo  '<div style="font:12px/1.35em arial, helvetica, sans-serif;">
<div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
<h3 style="margin:0; font-size:1.7em; font-weight:normal; text-transform:none; text-align:left; color:#2f2f2f;">
Whoops, it looks like you have an invalid PHP version.</h3></div><p>Magento supports PHP 5.3.0 or newer.
<a href="http://www.magentocommerce.com/install" target="">Find out</a> how to install</a>
 Magento using PHP-CGI as a work-around.</p></div>';
    exit;
}

/**
 * Error reporting
 */
error_reporting(E_ALL | E_STRICT);

/**
 * Compilation includes configuration file
 */
define('MAGENTO_ROOT', getcwd());

$compilerConfig = MAGENTO_ROOT . '/includes/config.php';
if (file_exists($compilerConfig)) {
    include $compilerConfig;
}

$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
$maintenanceFile = 'maintenance.flag';

if (!file_exists($mageFilename)) {
    if (is_dir('downloader')) {
        header("Location: downloader");
    } else {
        echo $mageFilename." was not found";
    }
    exit;
}

if (file_exists($maintenanceFile)) {
    include_once dirname(__FILE__) . '/errors/503.php';
    exit;
}

require_once $mageFilename;

#Varien_Profiler::enable();

if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
    Mage::setIsDeveloperMode(true);
}

#ini_set('display_errors', 1);

umask(0);

/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

//Mage::run($mageRunCode, $mageRunType);
switch($_SERVER['HTTP_HOST']){
	case 'service1cn.com':
	Mage::run('cn');
	break;
        case 'service2en.com':
	Mage::run('cn');
	break;
       case 'service3.com':
	Mage::run('main');
	break;
	default:
	Mage::run();
	break;
	
}

转载请注明:(●--●) Hello.My Weicot » win 下本地多域名解析+Apache多域名解析+Magento多域名解析一条龙

蜀ICP备15020253号-1