我正在为公司Intranet设置IIS7.5。 服务器将托pipe'testing'和'prod'网站。 我想为每个站点定制的环境variables是'PERL5LIB'。
我希望这个Web服务器包含一个Perl CGI(而不是FastCGI)环境。 (ActiveState Perl v5.16,使用PerlIs.dll和PerlEx30.dll)。 我希望这个Perl CGI环境具有“testing”和“产品”模块,因此testing模块可以在点击“testing”站点时加载。 同样,产品模块将在点击“产品”网站时加载。 每个站点设置PERL5LIB是关键。
Apache会使用与站点URL相关的SetEnv指令来做到这一点。
当然有可能,你使用两个不同的应用程序池,在不同的用户帐户下运行它们并设置基于用户的环境variables。
以下PowerShell脚本演示了如何执行此操作。 我在页面中使用ASP.NET,但你应该能够在Perl中做同样的事情。 您还需要启用IIS PowerShell脚本才能使用该脚本
Import-Module WebAdministration Function Prepare([string]$name,[int]$port) { # create a new directory for the site md c:\inetpub\site$name # create a new application pool New-WebAppPool "pool$name" # create a new site using the folder and pool we just created New-WebSite -name "site$name" -port $port -physicalpath "c:\inetpub\site$name" -applicationpool "pool$name" # Make sure the pool runs as applicationpoolidentity and loads its user profile set-webconfigurationproperty -pspath 'machine/webroot/apphost' -filter "system.applicationhost/applicationpools/add[@name='pool$name']/processmodel" -name "identitytype" -value "applicationpoolidentity" set-webconfigurationproperty -pspath 'machine/webroot/apphost' -filter "system.applicationhost/applicationpools/add[@name='pool$name']/processmodel" -name "loaduserprofile" -value "true" # create two pages, one to show the environment variable, the other to set it. "<%@ page %><html># <% response.write(system.environment.getenvironmentvariable(`"myvar`")) %> #</html>" | out-file "c:\inetpub\site$name\default.aspx" "<%@ page %><% system.environment.setenvironmentvariable(`"myvar`", `"i am site $name`", system.environmentvariabletarget.user) %>" | out-file "c:\inetpub\site$name\setenv.aspx" # hit the home page, just to get it started (new-object net.webclient).DownloadString("http://localhost:$port") # set our environment variable (new-object net.webclient).DownloadString("http://localhost:$port/setenv.aspx") # recycle the pool Restart-WebAppPool -Name "Pool$name" # wait a little bit to restart Start-Sleep -Milliseconds 500 # hit the home page again to show our variable (new-object net.webclient).DownloadString("http://localhost:$port") } # call the function for two sites Prepare A 81 Prepare B 82
我只在2012 R2上testing过,但是它应该在2008 R2上运行良好,不必使用脚本,可以在GUI中执行相同的步骤。