
로컬 IIS 인스턴스를 프록시로 사용하기 위해 개발 중인 로컬 Tomcat 서버가 있습니다.
내가 이렇게 하는 이유는 서버 배포가 많은 콘텐츠가 자체 포함되어 있지 않기 때문에 고통스러운 프로세스이기 때문입니다. 다른 프로젝트의 콘텐츠는 기본적으로 서버 루트에 복사됩니다. 저는 재작성 모듈의 도움으로 대부분의 경우 URL을 가상 디렉터리에 재작성할 수 있도록 설정하는 번거로움을 처리하고 싶지 않았습니다.
예:
/js/* -> /someproject/js/*
/css/* -> /someproject/css/*
/**/*.pdf -> /someotherproject/pdf/*
그러나 특히 대상 디렉터리에 중복이 있는 경우에는 이 구성표가 작동하지 않는 몇 가지 특수한 경우가 있습니다. 배포 시 일부 리소스는 동일한 디렉터리에 배치되므로 어느 리소스인지 구별할 수 있는 실제 방법이 없습니다. 이러한 파일에는 엄격한 패턴이 없으며 모두 혼합되어 있습니다.
예:
/someproject1/file1.txt -> /file1.txt
/someproject2/book2.doc -> /book2.doc
따라서 URL이 주어지면 또는 /file1.txt
로 이동하도록 다시 작성할 수 있는지 알 수 없습니다 . 그래서 재작성을 시도할 URL에 대한 일종의 계층 구조가 있다면 이 작업을 수행할 수 있을 것이라고 생각합니다. 따라서 와 같은 URL을 사용하여 유효한 것으로 보이는 첫 번째 패턴을 다시 작성할 수 있습니다.someproject1
someproject2
/file3.txt
/someproject1/file3.txt # if 404, try the next
/someproject2/file3.txt # if 404, try the next
/someotherproject/file3.txt # if 404, try the next
/file3.txt # fallback
이것은 URL 재작성 모듈을 통해서만 표현할 수 있는 것인가요?
답변1
나는 이것을 작동시킬 수있었습니다.
첫 번째 장애물은 전역 범위(내가 규칙을 작성하던 곳)에서 모든 조건부 일치 유형을 사용할 수 없다는 사실을 깨닫지 못했다는 것입니다. 만 Pattern
이용 가능했습니다. IsFile
및 일치 유형 에 액세스하려면 범위를 "분산" 범위(사이트별 규칙)로 변경해야 했습니다 IsDirectory
.
그런 다음 거기에서 일종의 계층 구조를 사용하여 규칙을 작성할 수 있습니다. 먼저 시도하고 싶은 패턴과 일치하도록 다시 작성하고, 파일로 해결되지 않으면 다음 패턴으로 다시 작성하여 반복합니다.
<rule name="try in project/content" stopProcessing="false">
<match url=".*" />
<action type="Rewrite" url="project/content/{R:0}" />
</rule>
<rule name="verify project/content" stopProcessing="false">
<match url="(project)/content(/.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}{R:2}" />
</rule>
내 특별한 경우에는 특정 하위 디렉터리를 먼저 시도한 다음 상위 디렉터리가 존재하지 않으면 시도하고 싶었습니다. 그러나 어떤 순서로 시도할지 아는 한 이론적으로는 모든 경로에 대해 이 작업을 수행할 수 있습니다.
따라서 질문의 예를 들어 다음 규칙을 설정하겠습니다.
<rule name="try in someproject1" stopProcessing="false">
<match url=".*" />
<action type="Rewrite" url="someproject1/{R:0}" />
</rule>
<rule name="try in someproject2 otherwise" stopProcessing="false">
<match url="someproject1/(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="someproject2/{R:1}" />
</rule>
<rule name="try in someotherproject otherwise" stopProcessing="false">
<match url="someproject2/(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="someotherproject/{R:1}" />
</rule>
<rule name="fallback to root otherwise" stopProcessing="false">
<match url="someotherproject/(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}" />
</rule>