Flask + Wfastcgi + IIS Express 关于虚拟目录的问题

2020-06-16 15:30:47 +08:00
 j0shfan
之前向大佬们请教如何在 win10 上部署 flask api 的问题
现在我的 API 通过 Flask + Wfastcgi + IIS Express 跑起来了,
然后出来一个问题,基于以上技术如何实现虚拟目录,

当前用户上传的文件,已经可以保存在 documents 的 IIS 站点目录下的 user-files 目录中
现要求,前端通过本 api 返回的虚拟目录地址,直接访问用户上传的文件

我尝试修改了 documents 中 IIS Express 的 applicationhost.config
1.将其中 directoryBrowse enabled 设为 true (不一定有关系)
2.并且在 sites 设定中,设置如下, 其中
<sites>
<site name="WebSite1" id="1" serverAutoStart="true">
<application path="/">
<virtualDirectory path="/" physicalPath="%IIS_SITES_HOME%\WebSite1" />
</application>
<application path="/user-uploaded-files">
<virtualDirectory path="/user-uploaded-files" physicalPath="%IIS_SITES_HOME%\WebSite1\user-files" />
</application>
<bindings>
<binding protocol="http" bindingInformation=":5000:localhost" />
<binding protocol="http" bindingInformation=":5000:10.5.220.75" />
</bindings>
</site>
<siteDefaults>
<logFile logFormat="W3C" directory="%IIS_USER_HOME%\Logs" />
<traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" maxLogFileSizeKB="1024" />
</siteDefaults>
<applicationDefaults applicationPool="Clr4IntegratedAppPool" />
<virtualDirectoryDefaults allowSubDirConfig="true" />
</sites>
3.请求的 url 为 10.5.220.75:5000/user-uploaded-files,结果在请求后返回 500.19 错误,也有时返回 WSGI handler 错误

500.19 错误如下

Detailed Error Information:



Module
IIS Web Core

Notification
BeginRequest

Handler
尚未确定

Error Code
0x8007000d

配置错误
找不到匹配的虚拟目录

配置文件




Requested URL
http://localhost:5000/user-uploaded-files/

Physical Path


Logon Method
尚未确定

Logon User
尚未确定

请求跟踪目录
C:\Users\Fanzexuan\Documents\IISExpress\TraceLogFiles\WEBSITE1


IIS 官方文档中,虚拟目录章节貌似也没说
https://docs.microsoft.com/en-us/iis/configuration/system.applicationhost/sites/site/application/virtualdirectory
wfastcgi 好像也没说关于虚拟目录的事情
https://pypi.org/project/wfastcgi/

请教各位是否我的虚拟目录中配置有问题,还是说需要一个叫 IIS web core module 的模块?(在 applicationhost.config 中没找到这个模块的设置),又或者我应该再独立弄一个站点
1903 次点击
所在节点    Python
4 条回复
ytymf
2020-06-16 16:24:14 +08:00
我当时配置的是 django,感觉基本上没遇到什么困难啊。。。。。除了 windows 上要注意下目录的权限问题。
基本上就是按照这篇文章的方法配置的静态资源,详见第七章
https://www.cnblogs.com/djangocn/p/10227006.html
j0shfan
2020-06-17 19:34:01 +08:00
@ytymf 多谢,老哥,我觉得这里面这个默认的虚拟目录 web.config 很有价值的,我这就试试!
j0shfan
2020-06-17 20:48:42 +08:00
@ytymf 可以了,老哥,在我自己电脑上配成了,多谢!
总结一下就是在 applicationhost.config 下,自己某个站点的配置中添加一个 application 的设置
<application path="/try-this">
<virtualDirectory path="/" physicalPath="C:\Users\User1\Documents\My Web Sites\WebSite1\myfiles" />
</application>
然后在这个文件夹下 C:\Users\User1\Documents\My Web Sites\WebSite1\myfiles 下添加 web.config,期间我遇到了 404.3error,因为我的文件夹中有个.webp 的文件,该拓展名和对应的 mime type 在的 applicationhost.config 默认设置中没有,下面是加上 mimemap 配置成功的 web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<!-- this configuration overrides the FastCGI handler to let IIS serve the static files -->
<handlers>
<clear/>
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
</handlers>
<staticContent>
<mimeMap fileExtension=".webp" mimeType="image/webp" />
</staticContent>
</system.webServer>
</configuration>
ytymf
2020-06-19 09:39:47 +08:00
@j0shfan 不客气,跟你也学到了。我没遇到困难的原因是没有特殊类型的文件,都是些常见的 js css 之类的,所以也不需要添加 mime

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/682066

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX