
회사 인트라넷용으로 IIS7.5를 설정하고 있습니다. 서버는 '테스트' 사이트와 '프로덕션' 사이트를 모두 호스팅합니다. 사이트별로 맞춤설정하고 싶은 환경변수는 'PERL5LIB' 입니다.
이 웹 서버에 Perl CGI(FastCGI 아님) 환경이 포함되기를 원합니다. (ActiveState Perl v5.16, PerlIs.dll 및 PerlEx30.dll 사용). 나는 이 Perl CGI 환경에 '테스트' 모듈과 '프로덕션' 모듈이 모두 있어서 '테스트' 사이트에 접속할 때 테스트 모듈이 로드될 수 있기를 원합니다. 마찬가지로 'prod' 사이트에 접속하면 prod 모듈이 로드됩니다. 사이트별로 PERL5LIB를 설정하는 것이 핵심입니다.
Apache는 사이트의 URL과 연결된 SetEnv 지시문을 사용하여 이를 수행합니다.
답변1
물론 가능합니다. 두 개의 서로 다른 응용 프로그램 풀을 사용하고 서로 다른 사용자 계정으로 실행하고 사용자 기반 환경 변수를 설정합니다.
다음 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에서만 테스트했지만 2008 R2에서는 제대로 실행되어야 합니다. 스크립트를 사용할 필요가 없으며 GUI에서 동일한 단계를 수행할 수 있습니다.