2016-09-25 9 views
0

私はAzureの書き換えルールは、

package.json 
server.js 
public 
    index.html 
    css 
    js 
    images 
...other folders 

は私だけで、パブリックフォルダ内の人を利用したいと思いNode.jsのアプリのためのルートに次のような構造を持つウェブサイトを持っています強制HTTPS接続。

私の現在のweb.configファイルには、この

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
    This configuration file is required if iisnode is used to run node processes behind 
    IIS or IIS Express. For more information, visit: 

    https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config 
--> 

<configuration> 
    <system.webServer> 
    <!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support --> 
    <webSocket enabled="false" /> 
    <handlers> 
     <!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module --> 
     <add name="iisnode" path="server.js" verb="*" modules="iisnode"/> 
    </handlers> 
    <rewrite> 
     <rules> 
     <!-- Do not interfere with requests for node-inspector debugging --> 
     <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true"> 
      <match url="^server.js\/debug[\/]?" /> 
     </rule> 

     <!-- First we consider whether the incoming URL matches a physical file in the /public folder --> 
     <rule name="StaticContent"> 
      <action type="Rewrite" url="public{REQUEST_URI}"/> 
     </rule> 

     <!-- All other URLs are mapped to the node.js site entry point --> 
     <rule name="DynamicContent"> 
      <conditions> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/> 
      </conditions> 
      <action type="Rewrite" url="server.js"/> 
     </rule> 

     <rule name="Force HTTPS" enabled="true"> 
      <match url="(.*)" ignoreCase="false" /> 
      <conditions> 
      <add input="{HTTPS}" pattern="off" /> 
      </conditions> 
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" /> 
     </rule>  

     <rule name="Redirect rquests to default azure websites domain" stopProcessing="true"> 
      <match url="(.*)" /> 
      <conditions logicalGrouping="MatchAny"> 
       <add input="{HTTP_HOST}" pattern="^zupbot\.azurewebsites\.net$" /> 
      </conditions> 
      <action type="Redirect" url="https://www.zup.chat/{R:0}" /> 
      </rule> 


     </rules> 
    </rewrite> 

    <!-- 'bin' directory has no special meaning in node.js and apps can be placed in it --> 
    <security> 
     <requestFiltering> 
     <hiddenSegments> 
      <remove segment="bin"/> 
     </hiddenSegments> 
     </requestFiltering> 
    </security> 

    <!-- Make sure error responses are left untouched --> 
    <httpErrors existingResponse="PassThrough" /> 

    <!-- 
     You can control how Node is hosted within IIS using the following options: 
     * watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server 
     * node_env: will be propagated to node as NODE_ENV environment variable 
     * debuggingEnabled - controls whether the built-in debugger is enabled 

     See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options 
    --> 
    <!--<iisnode watchedFiles="web.config;*.js"/>--> 
    </system.webServer> 
</configuration> 

のように見えます私は私のウェブサイトにアクセスしようとするたびに、それはserver.jsを発見しようとすると、私は、このエラー {「コード」を与える:「NotAuthorized」を、 「メッセージ」:「/ server.js」}

マイNode.jsのコードは、静的ファイルに

私はストレートのパブリックフォルダA内の人を取ることができますどのように
server.get('/.*/', restify.serveStatic({ 

    //Ensure that people can only access the files within the public directory and none of the protected server files 
    directory: __dirname + '/public', 
    default: constants.INDEX_HTML, 
    match: /^((?!server.js).)*$/ // we should deny access to the application source 
})); 

を提供するためにこれを行いますHTTPS接続が必要ですか?事前にあなたの助けをありがとう。 //.azurewebsites.net、それはまだ私を取る:私は私のネイティブサイトhttpに行く場合は、true stopProcessing =を持っており、それが動作する他のルールは、しかし前にHTTPSがリダイレクト追加

UPDATE 1

それのhttpsバージョンに、どのように私のカスタムドメインのhttpsバージョンにsitename.azurewebsites.netをリダイレクトできますか?

答えて

1

web.configに以下の書き換えルールを試してください:URL your_site.azurewebsites.net/<asset>あなたがrestify.serveStaticに設定され、パブリックフォルダ内の<asset>という名前のファイルがある場合、プロトコルhttpsに書き換えます

<rule name="DynamicContent" stopProcessing="true"> 
    <conditions> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/> 
    </conditions> 
    <action type="Rewrite" url="server.js"/> 
</rule> 

<rule name="Redirect to https" enabled="true" patternSyntax="ECMAScript" stopProcessing="true"> 
    <match url="(.*)"/> 
    <conditions> 
     <add input="{HTTPS}" pattern="Off"/> 
    </conditions> 
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" /> 
</rule> 

を。

あなたのrestifyアプリケーションのルート設定と一致するURLは書き換えません。

さらに詳しいことがありましたら、お気軽にお知らせください。