概要
<site>
構成要素は、IIS 7 以降のサーバーで実行する特定の Web サイトの構成を制御します。 たとえば、Default Web Site とその設定は、<sites>
要素の開始タグと終了タグの間にある <site>
要素で定義されます。
IIS 7 以降で新しい Web サイトを作成するときは、<site>
要素を構成します。 <site>
要素には、Web サイトに割り当てた名前を定義する name 属性と、Web サイトの数値識別子を定義する id 属性が含まれています。 <site>
要素には、サイトで実行されるアプリケーションと仮想ディレクトリ、および Web サイトのポート、プロトコル、ログ、トレースの構成設定を定義する子要素が含まれます。
互換性
バージョン | メモ |
---|---|
IIS 10.0 | <site> 要素は IIS 10.0 では変更されませんでした。 |
IIS 8.5 | <site> 要素は IIS 8.5 では変更されませんでした。 |
IIS 8.0 | <site> 要素は IIS 8.0 では変更されませんでした。 |
IIS 7.5 | <site> 要素は IIS 7.5 では変更されませんでした。 |
IIS 7.0 | <sites> コレクションの <site> 要素は IIS 7.0 で導入されました。 |
IIS 6.0 | <sites> コレクションは、IIS 6.0 の IIsWebServer メタベース オブジェクトを置き換えます。 |
段取り
<site>
要素は IIS 7 以降の既定のインストールに含まれています。
操作方法
IIS 7 で新しい Web サイトを構成するときは、Web サイトにサイト名と物理パスを割り当てる必要があります。 省略可能な構成設定もいくつか設定できます。 IIS 7 サーバーで既定の Web サイトを引き続き使用する場合は、新しいサイトのバインド情報を変更する必要があります。 ポートを変更するか、新しい Web サイトのホスト名を入力して、これを実行できます。
新しい Web サイトを作成する方法
次のようにインターネット インフォメーション サービス (IIS) マネージャーを開きます。
Windows Server 2012 または Windows Server 2012 R2 を使用している場合:
- タスク バーで、[サーバー マネージャー] をクリックし、[ツール]、[インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
Windows 8 または Windows 8.1 を使用している場合:
- Windows キーを押しながら文字 X を押し、[コントロール パネル] をクリックします。
- [管理ツール] をクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
Windows Server 2008 または Windows Server 2008 R2 を使用している場合:
- タスク バーで、[スタート] ボタンをクリックし、[管理ツール]、[インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
Windows Vista または Windows 7 を使用している場合:
- タスク バーで、[スタート]、[コントロール パネル] の順にクリックします。
- [管理ツール] をダブルクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
[接続] ウィンドウでサーバー名を展開し、[サイト] をクリックします。
[操作] ウィンドウで [Web サイトの追加...] をクリックします。
[Web サイトの追加] ダイアログ ボックスで、少なくとも [サイト名] テキスト ボックスと [物理パス] テキスト ボックスに情報を入力し、[ホスト名] テキスト ボックスに情報を入力するか、[ポート] ボックスの数値を変更するかを選択します。
IIS マネージャーで更新ボタンをクリックして、サイトが開始されたことを確認します。
FTP サイトに対する匿名認証を有効または無効にする方法
次のようにインターネット インフォメーション サービス (IIS) マネージャーを開きます。
Windows Server 2012 または Windows Server 2012 R2 を使用している場合:
- タスク バーで、[サーバー マネージャー] をクリックし、[ツール]、[インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
Windows 8 または Windows 8.1 を使用している場合:
- Windows キーを押しながら文字 X を押し、[コントロール パネル] をクリックします。
- [管理ツール] をクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
Windows Server 2008 または Windows Server 2008 R2 を使用している場合:
- タスク バーで、[スタート] ボタンをクリックし、[管理ツール]、[インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
Windows Vista または Windows 7 を使用している場合:
- タスク バーで、[スタート]、[コントロール パネル] の順にクリックします。
- [管理ツール] をダブルクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
[接続] ウィンドウでサーバー名を展開し、[サイト] ノードを展開してから、サイトの名前をクリックします。
サイトの [ホーム] ウィンドウで、[FTP 認証] 機能をダブルクリックします。
[FTP 認証] ページで、[匿名認証] を選びます。
[操作] ウィンドウで、[有効にする] をクリックして匿名認証を有効にするか、[無効にする] をクリックして匿名認証を無効にします。
FTP サイト ウィザードを使用して匿名読み取りアクセス権を指定して FTP サイトを作成する方法
次のようにインターネット インフォメーション サービス (IIS) マネージャーを開きます。
Windows Server 2012 または Windows Server 2012 R2 を使用している場合:
- タスク バーで、[サーバー マネージャー] をクリックし、[ツール]、[インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
Windows 8 または Windows 8.1 を使用している場合:
- Windows キーを押しながら文字 X を押し、[コントロール パネル] をクリックします。
- [管理ツール] をクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
Windows Server 2008 または Windows Server 2008 R2 を使用している場合:
- タスク バーで、[スタート] ボタンをクリックし、[管理ツール]、[インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
Windows Vista または Windows 7 を使用している場合:
- タスク バーで、[スタート]、[コントロール パネル] の順にクリックします。
- [管理ツール] をダブルクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
[接続] ペインで、ツリーにある [サイト] ノードをクリックします。
ツリーの [サイト] ノードを右クリックし、[FTP サイトの追加] をクリックするか、[操作] ペインの [FTP サイトの追加] をクリックします。
FTP サイトの追加ウィザードが表示されたら次の操作を行います。
FTP サイトの追加ウィザードの 2 番めのページで、次の操作を行います。
[IP アドレス] ドロップダウンから FTP サイトの IP アドレスを選択するか、既定の選択値である [すべて未割り当て] を受け入れます。
[ポート] ボックスに FTP サイトの TCP/IP ポートを入力します。 既定では、FTP サイトとクライアントはポート 21 を使用します。 (注: 暗黙的 FTPS を指定するには、ポート 990 を使用する必要があります)。
FTP 仮想ホスト名を使用するには、[仮想ホスト名を有効にする] ボックスをオンにし、[仮想ホスト] ボックスに仮想ホスト名を入力します。
SSL オプションに、次のいずれかのオプションを選びます。
- SSL オプションを無効にするには、SSL に [無し] を選びます。
- FTP クライアントが FTP サーバーに接続するときに、必要に応じて FTP over SSL を使用できるようにするには、SSL に [許可] を選びます。
- FTP クライアントが FTP サーバーに接続するときに、常に FTP over SSL を使用できるようにするには、SSL に [必要] を選びます。
- SSL に [許可] または [必要] を選択した場合は、[SSL 証明書] ドロップダウン メニューから証明書を選択します。
次のウィザード ページで次の操作を行います。
構成
<site>
要素は、ApplicationHost.config ファイルにサーバー レベルで構成します。
属性
属性 | 説明 |
---|---|
id |
省略可能な uint 属性。 サイトの作成時に IIS が割り当てるランダムな数値識別子を指定します。 Default Web Site の番号は 1 です。 他の Web サイトには、複数の数字で構成されるランダムな数が割り当てられます。 |
name |
省略可能な文字列属性。 Web サイトを一意に識別するフレンドリ名 (たとえば、"Contoso HR Forms") を指定します。 |
serverAutoStart |
省略可能な Boolean 属性です。 管理サービスの開始時にサイトを自動的に開始するかどうかを指定します。 既定値は true です。 |
子要素
要素 | 説明 |
---|---|
application |
省略可能な要素です。 サイト内のアプリケーションの構成設定のコレクションを指定します。 |
applicationDefaults |
省略可能な要素です。 親サイト内のすべてのアプリケーションの既定の設定を指定します。 |
bindings |
省略可能な要素です。 サイトにアクセスするためのバインドを指定します。 |
ftpServer |
省略可能な要素です。 サイトの FTP 設定を指定します。 注: これには、FTP 7.0 または FTP 7.5 をインストールする必要があります。 |
limits |
省略可能な要素です。 設定を構成して、サイトへの接続の帯域幅の量、接続数、または接続時間を制限します。 |
logFile |
省略可能な要素です。 サイトのログ ファイルの処理とストレージの設定を構成します。 |
traceFailedRequestsLogging |
省略可能な要素です。 サイトの失敗した要求トレースをログするための設定を指定します。 |
virtualDirectoryDefaults |
省略可能な要素です。 サーバー上のすべての仮想ディレクトリの既定の設定を指定します。 |
構成サンプル
次の構成例は、ApplicationHost.config ファイルの <site>
要素を示しています。 name 属性はサイト名を Contoso として定義し、id 属性は IIS 固有の識別子を 2 に定義します。 <virtualDirectory>
要素の physicalPath 属性は、新しいサイトのコンテンツの物理的な場所を定義します。 <binding>
要素の protocol 属性はサイトが使用するプロトコルを定義し、bindingInformation 属性は新しい Web サイトが使用するホスト ヘッダーとして www.contoso.com
を定義します。
<site name="Contoso" id="2">
<application path="/">
<virtualDirectory path="/" physicalPath="C:\inetpub\Contoso" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:80:www.contoso.com" />
</bindings>
</site>
サンプル コード
次の例は、ID が 2 の Contoso という名前の新しい Web サイトを作成し、ポート 80 経由の HTTP プロトコルのバインドを "www.contoso.com" というホスト ヘッダーを使用して設定します。 新しい Web サイトの物理パスは C:\Inetpub\www.contoso.com\wwwroot です。
AppCmd.exe
appcmd.exe set config -section:system.applicationHost/sites /+"[name='Contoso',id='2',serverAutoStart='True']" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites /+"[name='Contoso',id='2'].bindings.[protocol='http',bindingInformation='*:80:www.contoso.com']" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites /+"[name='Contoso',id='2'].[path='/']" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites /+"[name='Contoso',id='2'].[path='/'].[path='/',physicalPath='C:\Inetpub\www.contoso.com\wwwroot']" /commit:apphost
Note
AppCmd.exe を使用してこれらの設定を構成するときは、commit パラメーターを必ず apphost
に設定する必要があります。 これで、ApplicationHost.config ファイルの適切な場所セクションに構成設定がコミットされます。
C#
using System;
using System.Text;
using Microsoft.Web.Administration;
internal static class Sample
{
private static void Main()
{
using (ServerManager serverManager = new ServerManager())
{
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites");
ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();
ConfigurationElement siteElement = sitesCollection.CreateElement("site");
siteElement["name"] = @"Contoso";
siteElement["id"] = 2;
siteElement["serverAutoStart"] = true;
ConfigurationElementCollection bindingsCollection = siteElement.GetCollection("bindings");
ConfigurationElement bindingElement = bindingsCollection.CreateElement("binding");
bindingElement["protocol"] = @"http";
bindingElement["bindingInformation"] = @"*:80:www.contoso.com";
bindingsCollection.Add(bindingElement);
ConfigurationElementCollection siteCollection = siteElement.GetCollection();
ConfigurationElement applicationElement = siteCollection.CreateElement("application");
applicationElement["path"] = @"/";
ConfigurationElementCollection applicationCollection = applicationElement.GetCollection();
ConfigurationElement virtualDirectoryElement = applicationCollection.CreateElement("virtualDirectory");
virtualDirectoryElement["path"] = @"/";
virtualDirectoryElement["physicalPath"] = @"C:\Inetpub\www.contoso.com\wwwroot";
applicationCollection.Add(virtualDirectoryElement);
siteCollection.Add(applicationElement);
sitesCollection.Add(siteElement);
serverManager.CommitChanges();
}
}
}
VB.NET
Imports System
Imports System.Text
Imports Microsoft.Web.Administration
Module Sample
Sub Main()
Dim serverManager As ServerManager = New ServerManager
Dim config As Configuration = serverManager.GetApplicationHostConfiguration
Dim sitesSection As ConfigurationSection = config.GetSection("system.applicationHost/sites")
Dim sitesCollection As ConfigurationElementCollection = sitesSection.GetCollection
Dim siteElement As ConfigurationElement = sitesCollection.CreateElement("site")
siteElement("name") = "Contoso"
siteElement("id") = 2
siteElement("serverAutoStart") = True
Dim bindingsCollection As ConfigurationElementCollection = siteElement.GetCollection("bindings")
Dim bindingElement As ConfigurationElement = bindingsCollection.CreateElement("binding")
bindingElement("protocol") = "http"
bindingElement("bindingInformation") = "*:80:www.contoso.com"
bindingsCollection.Add(bindingElement)
Dim siteCollection As ConfigurationElementCollection = siteElement.GetCollection
Dim applicationElement As ConfigurationElement = siteCollection.CreateElement("application")
applicationElement("path") = "/"
Dim applicationCollection As ConfigurationElementCollection = applicationElement.GetCollection
Dim virtualDirectoryElement As ConfigurationElement = applicationCollection.CreateElement("virtualDirectory")
virtualDirectoryElement("path") = "/"
virtualDirectoryElement("physicalPath") = "C:\Inetpub\www.contoso.com\wwwroot"
applicationCollection.Add(virtualDirectoryElement)
siteCollection.Add(applicationElement)
sitesCollection.Add(siteElement)
serverManager.CommitChanges()
End Sub
End Module
JavaScript
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST");
var sitesCollection = sitesSection.Collection;
var siteElement = sitesCollection.CreateNewElement("site");
siteElement.Properties.Item("name").Value = "Contoso";
siteElement.Properties.Item("id").Value = 2;
siteElement.Properties.Item("serverAutoStart").Value = true;
var bindingsCollection = siteElement.ChildElements.Item("bindings").Collection;
var bindingElement = bindingsCollection.CreateNewElement("binding");
bindingElement.Properties.Item("protocol").Value = "http";
bindingElement.Properties.Item("bindingInformation").Value = "*:80:www.contoso.com";
bindingsCollection.AddElement(bindingElement);
var siteCollection = siteElement.Collection;
var applicationElement = siteCollection.CreateNewElement("application");
applicationElement.Properties.Item("path").Value = "/";
var applicationCollection = applicationElement.Collection;
var virtualDirectoryElement = applicationCollection.CreateNewElement("virtualDirectory");
virtualDirectoryElement.Properties.Item("path").Value = "/";
virtualDirectoryElement.Properties.Item("physicalPath").Value = "C:\\Inetpub\\www.contoso.com\\wwwroot";
applicationCollection.AddElement(virtualDirectoryElement);
siteCollection.AddElement(applicationElement);
sitesCollection.AddElement(siteElement);
adminManager.CommitChanges();
VBScript
Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST")
Set sitesCollection = sitesSection.Collection
Set siteElement = sitesCollection.CreateNewElement("site")
siteElement.Properties.Item("name").Value = "Contoso"
siteElement.Properties.Item("id").Value = 2
siteElement.Properties.Item("serverAutoStart").Value = True
Set bindingsCollection = siteElement.ChildElements.Item("bindings").Collection
Set bindingElement = bindingsCollection.CreateNewElement("binding")
bindingElement.Properties.Item("protocol").Value = "http"
bindingElement.Properties.Item("bindingInformation").Value = "*:80:www.contoso.com"
bindingsCollection.AddElement bindingElement
Set siteCollection = siteElement.Collection
Set applicationElement = siteCollection.CreateNewElement("application")
applicationElement.Properties.Item("path").Value = "/"
Set applicationCollection = applicationElement.Collection
Set virtualDirectoryElement = applicationCollection.CreateNewElement("virtualDirectory")
virtualDirectoryElement.Properties.Item("path").Value = "/"
virtualDirectoryElement.Properties.Item("physicalPath").Value = "C:\Inetpub\www.contoso.com\wwwroot"
applicationCollection.AddElement(virtualDirectoryElement)
siteCollection.AddElement applicationElement
sitesCollection.AddElement siteElement
adminManager.CommitChanges()