Edgewall Software

Changes between Initial Version and Version 1 of CookBook/Installation/TracOnWindowsIisWfastcgi


Ignore:
Timestamp:
Feb 22, 2015, 3:21:25 AM (9 years ago)
Author:
bob.hyman@…
Comment:

It works!

Legend:

Unmodified
Added
Removed
Modified
  • CookBook/Installation/TracOnWindowsIisWfastcgi

    v1 v1  
     1= IIS configuration for Trac 1.0x and IIS 7.5 (windows server 2012 and Windows 8)
     2
     3[[TOC]]
     4
     5== what you get
     6[http://trac.edgewall.org/ Trac] using [http://trac.edgewall.org/wiki/TracModWSGI WSGI] interface hosted by Microsoft IIS using FastCGI handler.
     7
     8Static content served by IIS rather than through Trac.
     9
     10Windows Authentication, if you want it, done by IIS, but authorization managed via Permissions in Trac. No need for [http://trac-hacks.org/wiki/AccountManagerPlugin AccountManagerPlugin].
     11
     12== What You Need
     13Windows Server 2012 or Windows 8 Professional with IIS 7.5 installed.
     14
     15The [http://www.iis.net/downloads/microsoft/url-rewrite URL Rewrite extension] for your version of IIS. 
     16
     17[http://pytools.codeplex.com/releases/view/109707 FastCGI.py ] from the Python Tools for Visual Studio project.  This is the indispensible glue, all props to the PTVS folks for providing it.
     18
     19== Disclaimers
     20Probably works for IIS 7.0 or IIS Express (free!) on Windows Server 2008r2 or Windows 7, but I have not tested it, and won't be doing so.
     21
     22I have not tried to generalize for collection of Trac environments under a common parent.
     23
     24This configuration only allows 1 Trac site (environment or parent) per IIS server, because the FastCGI application is defined at the server level and is identified by executable + arguments.  To support multiple Trac virtual directories (on default or additional websites, doesn't matter), you might be able to clone wFastCgi.py with different names and different hardcoded environment variable settings, or hack it to accept environment variable definitions from the command line.  Either way, you could then define multiple FastCGI applications with different command line arguments and they would be distinguishable by IIS. 
     25
     26== What Goes Where
     27 `<virtualenv>` (in examples below, N:\vePython\trac27)::
     28 contains Python interpreter, Trac and plugins.  As the name implies, I used a python virtual environment rather than the main install.  I don't think it matters.
     29 `<tracVDir>` (C:\inetpub\wwwroot\tracWSGI)::
     30 the physical path to an IIS virtual directory, e.g `c:\inetpub\wwwroot\trac`.  Contains the static content for your Trac environments.  This does not need to be a separate site or a .net application under IIS, just a virtual directory.
     31 `<tracEnv>`(N:\tracenv\tracWSGI)::
     32 Trac environment somewhere not under IIS.  \\Not a requirement, but how I happened to have Trac already running.
     33 `<tracURL>` (!http://localhost/tracWSGI)::
     34 The URL of the Trac environment.
     35
     36== Configuration Steps
     37(I apologize for using the IIS command line here. It is concise and unambiguous, but finickey.  But trying to describe gestures in the GUI would be even worse.)
     38
     39=== Install CGI and FastCGI handler in IIS:
     40{{{
     41      c:\> start /w pkgmgr /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-LoggingLibraries;IIS-RequestMonitor;IIS-Security;IIS-RequestFiltering;IIS-HttpCompressionStatic;IIS-WebServerManagementTools;IIS-ManagementConsole;WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI;IIS-CGI
     42}}}
     43   See [http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/enable-fastcgi-support-in-iis-7-on-windows-server-2008-windows-server-2008-r2-windows-vista-or-windows-7 here] for GUI.
     44
     45=== Download and install URL Rewrite extension
     46
     47From [http://www.iis.net/downloads/microsoft/url-rewrite here].
     48
     49Rules get configured [#configureRewrite below] 
     50
     51=== Deploy static content from Trac into IIS:
     52
     53`trac-admin <tracEnv> deploy <tracVDir>`
     54
     55=== Configure the FastCGI application at the IIS server root.
     56
     57Note that IIS only supports one FastCGI application with a given executable and command line.  So you're limited to a single Trac environment per IIS server unless you get creative with wFastCgi.py.
     58
     59FastCGI application invokes Python interpreter (from `<virtualenv>`) running `wfastcgi.py` as the argument.  `wfastcgi.py` needs 3 or 4 environment variables.
     60
     61{{{
     62c:\> appcmd.exe set config -section:system.webServer/fastCgi ^
     63         /+"fullPath='`<virtualenv>` N:\vePython\trac27\Scripts\python.exe', arguments='n:\vePython\trac27\scripts\wfastcgi.py'"
     64c:\>appcmd.exe set config -section:system.webServer/fastCgi ^
     65         /+"[fullPath='N:\vePython\trac27\Scripts\python.exe'].environmentVariables.[name='TRAC_ENV_PATH', value='n:\tracenv\tracWSGI']" /commit:apphost
     66c:\>appcmd.exe set config -section:system.webServer/fastCgi ^
     67         /+"[fullPath='N:\vePython\trac27\Scripts\python.exe'].environmentVariables.[name='PYTHON_EGG_CACHE', value='n:\tracenv\tracWSGI.egg-cache']" /commit:apphost
     68c:\>appcmd.exe set config -section:system.webServer/fastCgi ^
     69         /+"[fullPath='N:\vePython\trac27\Scripts\python.exe'].environmentVariables.[name='WSGI_HANDLER', value='trac.web.main.dispatch_request']" /commit:apphost
     70}}}
     71
     72=== Configure the Handler Map in the Trac virtual directory to invoke the FastCGI application
     73
     74{{{
     75c:\> appcmd.exe set config "Default Web Service/tracWSGI" -section:system.webServer/handlers ^
     76          /+"name='Python_FastCGI_WSGI', path='*', verb='*', modules='FastCgiModule', scriptProcessor='n:\vePython\trac27\scripts\python.exe|n:\vePython\trac27\scripts\wfastcgi.py', resourceType='Unspecified', requireAccess='Script'"
     77}}}
     78
     79The `ResourceType=Unspecified` is key: otherwise IIS insists that the URI match a file in `<tracVdir>` before invoking the handler.
     80
     81=== [=#configureRewrite Add rewrite rule(s)]
     82
     83These rewrite `chrome/common/...` and `chrome/site/...` to `htdocs/common/...` and `htdocs/site/...`, respectively. 
     84
     85{{{
     86c:\> appcmd.exe set config "Default Web Site/tracWSGI" -section:system.webServer/rewrite/rules ^
     87         /+"[name='siteToHtdocs',stopProcessing='True']" /commit:apphost
     88c:\> appcmd.exe set config "Default Web Site/tracWSGI" -section:system.webServer/rewrite/rules ^
     89         /[name='siteToHtdocs',stopProcessing='True'].match.url:"chrome/site/(.*)"  /commit:apphost
     90c:\> appcmd.exe set config "Default Web Site/tracWSGI" -section:system.webServer/rewrite/rules /[name='siteToHtdocs',stopProcessing='True'].action.type:"Rewrite" ^
     91         /[name='siteToHtdocs',stopProcessing='True'].action.url:"htdocs/site/{R:1}" ^
     92         /[name='siteToHtdocs',stopProcessing='True'].action.logRewrittenUrl:"True"  /commit:apphost
     93
     94c:\> appcmd.exe set config "Default Web Site/tracWSGI" -section:system.webServer/rewrite/rules ^
     95         /+"[name='commonToHtdocs',stopProcessing='True']" /commit:apphost
     96c:\> appcmd.exe set config "Default Web Site/tracWSGI" -section:system.webServer/rewrite/rules ^
     97         /[name='commonToHtdocs',stopProcessing='True'].match.url:"chrome/common/(.*)"  /commit:apphost
     98c:\> appcmd.exe set config "Default Web Site/tracWSGI" -section:system.webServer/rewrite/rules /[name='commonToHtdocs',stopProcessing='True'].action.type:"Rewrite" ^
     99         /[name='commonToHtdocs',stopProcessing='True'].action.url:"htdocs/common/{R:1}" ^
     100         /[name='commonToHtdocs',stopProcessing='True'].action.logRewrittenUrl:"True"  /commit:apphost
     101}}}
     102
     103There is some magic here: we configure the FastCGI handler to handle *all* URIs under the virtual directory, but also tell rewrite to edit URIs under <vdir>/chrome.  Somehow, IIS understands that the rewritten URI should not be passed to FastCGI.  But why?
     104
     105=== Enable Windows authentication, disable anonymous (if you aren't using http://trac-hacks.org/wiki/AccountManagerPlugin AccountManagerPlugin])
     106
     107Trac receives the authenticated user name and greets him/her as a logged in user.
     108
     109{{{
     110c:\> appcmd.exe set config "Default Web Site/tracWSGI" -section:system.webServer/security/authentication/anonymousAuthentication /enabled:"False"  /commit:apphost
     111c:\> appcmd.exe set config "Default Web Site/tracWSGI" -section:system.webServer/security/authentication/windowsAuthentication /enabled:"True"  /commit:apphost
     112}}}
     113
     114
     115[[BackLinks]]