0

I'm trying to set up a Django/Angular application under IIS.

When I set a similar application under nginx, I pass all URLs starting with /api (my backend) or /admin (the Django admin interface) to Django. I also set two locations: / and /static - both are aliases to the folder with all the static resources.

I need to alias /static, too, because Django's admin application references resources at /static/admin/...

I can't get IIS to work the same way. I'm using wfastcgi to interface with Django, and a rewrite rule to map /static back to /. This is the relevant portion of my Web.config:

<rewrite>
    <rules>
        <rule name="Static Perfix" stopProcessing="true" >
            <match url="^static/(.+)" />
            <action type="Rewrite" url="{R:1}" />
        </rule>
    </rules>
</rewrite>
<handlers>
    <add name="Admin" 
         path="/admin" 
         verb="*" 
         modules="FastCgiModule" 
         scriptProcessor="..." 
         resourceType="Unspecified" />
</handlers>

This doesn't work. When I access /admin the handler catches it and forwards the request to Django, as it should. Django return an html page with resources located at /static/admin/base.css (for example).

When the browser tries to load such a resource the rewrite rule catches it, rewrites it to /admin/base.css, and then the handler catches it and forwards it to Django, which doesn't know what /admin/base.css is and returns a 404.

I tried making /static a Virtual Directory pointing to the same physical directory as the root directory. This caused all sorts of conflicts because my root Web.config was read twice, causing all sorts of duplicate key violations (for all the keys I have defined, more or less).

I would appreciate any help on getting out of this situation.

zmbq
  • 38,013
  • 14
  • 101
  • 171

1 Answers1

0

I ended up avoiding the problem altogether, by restructuring my static resources folder and adding an actual static subfolder that contains the Admin static files.

I will no longer be able to use manage.py collectstatic for front-end deployment, though, I will need to create an additional script. Oh well.

zmbq
  • 38,013
  • 14
  • 101
  • 171