豚吐露@wiki

IISExpressで外部からの接続を許可したい

最終更新:

Bot(ページ名リンク)

- view
管理者のみ編集可

IISExpressで外部からの接続を許可したい

Windows 7 Professional
IIS Express 8.5(Visual Studio 2013 Professional)

まず、以下のfileを開く。
C:\Users\【ユーザ名】\Documents\IISExpress\config\applicationhost.config
開いたら<site>タグを検索。
これがIISで言う『インターネット インフォメーション サービス (IIS) マネージャー』の設定。

  1. <site name="【サイト名】" id="【ID】">
  2. <application path="/" applicationPool="【アプリケーションプール名】">
  3. <virtualDirectory path="【エイリアス名】" physicalPath="【dir path】" />
  4. </application>
  5. <bindings>
  6. <binding protocol="http" bindingInformation="*:80:localhost" />
  7. </bindings>
  8. </site>

site → name サイト名は任意のものに変えると、VS上で反映される。
site → id IDはIISExpressが自動採番。
site/application → path site rootからどこに配置するか指定。
site/application → applicationPool アプリケーションプール名。特殊な場合を除いて、変更する必要無し。
site/bindings/binding → protocol プロトコルの指定。http。
site/bindings/binding → bindingInformation 接続許可を指定。『:80:localhost』でPort 80へlocalhostがアクセスできる。
『:80:192.168.1.10』って書くと192.168.1.10:80へのアクセスを許可する。つまりココにIISExpressが動いてるマシンのIP Addressを書いとけばokって話。

以上のルールに従って書いてみるとこんな感じ。
e.g.) IIS Expressが動くマシンのIP Addressが『192.168.1.10』の場合
  1. <site name="TestSite" id="25">
  2. <application path="/" applicationPool="Clr4IntegratedAppPool">
  3. <virtualDirectory path="/" physicalPath="C:\asp.net_test\testsite" />
  4. <virtualDirectory path="/test2" physicalPath="C:\asp.net_test\testsite2" />
  5. </application>
  6. <application path="/api" applicationPool="Clr4IntegratedAppPool">
  7. <virtualDirectory path="/" physicalPath="C:\asp.net_test\webapi" />
  8. </application>
  9. <bindings>
  10. <binding protocol="http" bindingInformation="*:80:localhost" />
  11. <binding protocol="http" bindingInformation="*:80:192.168.1.10" />
  12. </bindings>
  13. </site>

コンフィグファイルをいじったら、

以下のコマンドを、コマンドプロンプトで実行。IP addressの部分だけIIS Express動かしてるヤツのIPに変えて解釈して貰えればOK。
> netsh.exe http add urlacl url=http://192.168.1.10:80/ user=everyone


後はfirewall。
コントロールパネルを開いて『Windows ファイアウォール』を押下。
ダイアログが表示されたら左のメニューから『詳細設定』を選択して、『セキュリティが強化された Windows ファイアウォール』ダイアログを開く。

左側に表示されてるツリーから『受信の規則』を右クリックして、『新しい規則』を押下。
『新規の受信の規則ウィザード』が開くので...

『ポート』を選択して、『次へ』押下。

『TCP』の『80』を指定して『次へ』押下。

『接続を許可する』を選択して『次へ』押下。

とりあえず、怖いので『パブリック』のチェックは外して『次へ』押下。

名前に分かりやすいの設定して『完了』押下。

コレで外部のマシンのブラウザから『http://192.168.1.10』とか入れてみると表示できるハズ。


もし繋がらんかったら、上記を見直してみること。

接続がタイムアウトしたら、Firewallで防がれてる。

503返ってきたら、IISExpressを再起動してみる。
再起動は、VisualStudioのデバッグを停止させて、IISExpressを終了、デバッグを開始とすれば良い。

※IISExpressの終了の仕方
↓こんなアイコンがシステムトレイ内に常駐してたら、設定が反映されてない可能性有り。
システムトレイ内のアイコンを右クリックして『終了』を選択すればOK。



更新日: 2015年04月10日 (金) 17時35分40秒

名前:
コメント:

すべてのコメントを見る
記事メニュー
ウィキ募集バナー