
Estou configurando o IIS7.5 para uma intranet corporativa. O servidor hospedará um site de 'teste' e um site de 'produção'. A variável de ambiente que desejo personalizar por site é 'PERL5LIB.
Quero que este servidor web contenha um ambiente Perl CGI (não FastCGI). (ActiveState Perl v5.16, usando PerlIs.dll e PerlEx30.dll). Eu quero que este ambiente Perl CGI tenha módulos de 'teste' e 'prod', para que os módulos de teste possam ser carregados ao acessar o site de 'teste'. Da mesma forma, os módulos prod serão carregados ao acessar o site 'prod'. Definir PERL5LIB por site é a chave.
O Apache faria isso com uma diretiva SetEnv associada à URL do site.
Responder1
Claro que é possível, você usa dois pools de aplicativos diferentes, executa-os em contas de usuário diferentes e define variáveis de ambiente baseadas no usuário.
O script do PowerShell a seguir demonstra como fazer isso. Estou usando ASP.NET nas páginas, mas você deve conseguir fazer o mesmo em Perl. Você também precisa do script IIS PowerShell habilitado para usar o script
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
Eu testei isso apenas no 2012 R2, mas deve funcionar bem no 2008 R2, você não precisa usar o script, você pode seguir os mesmos passos na GUI.