昨天碰到了一個關於IIS映射的問題,在上網查了好多資料都說的特別模糊,要不然就是只告訴你怎么配置不告訴你是干嘛的,要不然就是說的特別不清楚不知道他寫的是啥,后來查了微軟官方文檔(真坑啊還是得自己看文檔)才搞明白,下面是我對IIS處理映射的理解。
官方對處理映射的解釋是:
Handlers are Internet Information Services (IIS) components that are configured to process requests to specific content, typically to generate a response for the request resource. For example, an ASP.NET Web page is one type of handler. You can use handlers to process requests to any resource that needs to return information to users that is not a static file. IIS provides several different handler types to support static files, Common Gateway Interface (CGI) applications, FastCGI applications, and Internet Server API (ISAPI) extensions. ASP.NET also provides support for additional handler types through the HTTP handler interface.
Developers can create custom handlers to perform special handling that you can identify using file name extensions in your application. For example, if a developer created a handler that created RSS-formatted XML, you could bind the .rss file name extension in your application to the custom handler. Developers can also create handlers that map to a specific file and can implement these handlers as native modules or as implementations of the ASP.NET IHttpHandler interface.
差不多意思就是處理映射用於對特定請求的響應,用自定義后綴來識別,之后添加你處理這個后綴需要的腳本命令,比如.exe,.dll,然后iis接收到這個請求之后會是用你指定的腳本來處理這個請求。比如說你的網站是Asp.net,但現在可能需要處理某個.php的響應,那么這個時候就要用到處理映射了。
詳細的步驟是:
1.打開IIS,定位到你要添加處理映射的網站,點擊Handler Mappings菜單后點擊Add Module Mapping。
2.在下圖中添加特殊請求的后綴名,比如*.php。
3.在Moudle下拉列表中選擇你的Moudle,比如這個例子的FastCgiMoudle。
4.指定你的腳本處理程序路徑,比如我要處理php文件所用的php-cgi.exe。
5.將指定資源放入你的web網站的目錄里,比如我這個是一個index.php,那么我就把這個文件放在我的web目錄里(C:\inetpub\wwwroot)。
6.測試,在路徑里輸入你要請求的資源,我這個例子里是(http://localhost/index.php)。
參考的官方文檔地址: https://docs.microsoft.com/en-us/iis/configuration/system.webserver/handlers/
https://docs.microsoft.com/en-us/iis/configuration/system.webserver/handlers/add