官方文档
微软官方文档地址:https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/reverse-proxy-with-url-rewrite-v2-and-application-request-routing
模块下载
iis 重写下载模块地址: https://www.iis.net/downloads/microsoft/url-rewrite
安装后会有这个模块
iis 部署 django + vue (使用反向代理实现服务器对外只暴露一个端口)
例:
服务器 windows server 2019
对外暴露 端口:8001
django端口:8000
vue端口:8002
按照官方文档的demo测试一遍没问题。
在服务器尝试仍然报 404 。
发现 vue 的 js 404
解决方法:
iis重写url 里 添加vue打包后js,css,fonts,img路径
django 报404 仍未想明白
可能和下面一些操作有关(实在是不想在捣鼓它了,折磨人)
1.添加功能后重启
多出了下面的文件,本来没有这些文件
添加功能如下(有些功能也不知道具体啥作用,加就完了)
服务器角色
功能
最后web.config 配置
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Reverse Proxy to account" stopProcessing="true">
<match url="^account/(.*)" />
<action type="Rewrite" url="http://localhost:8000/{R:0}" />
</rule>
<rule name="Reverse Proxy to api" stopProcessing="true">
<match url="^api/(.*)" />
<action type="Rewrite" url="http://localhost:8000/{R:0}" />
</rule>
<rule name="Reverse Proxy to vue" stopProcessing="true">
<match url="^login/(.*)" />
<action type="Rewrite" url="http://localhost:8002/{R:1}" />
</rule>
<rule name="Reverse Proxy to vuejs" stopProcessing="true">
<match url="^js/(.*)" />
<action type="Rewrite" url="http://localhost:8002/{R:0}" />
</rule>
<rule name="Reverse Proxy to vuescc" stopProcessing="true">
<match url="^css/(.*)" />
<action type="Rewrite" url="http://localhost:8002/{R:0}" />
</rule>
<rule name="Reverse Proxy to vueexcel" stopProcessing="true">
<match url="^excel/(.*)" />
<action type="Rewrite" url="http://localhost:8002/{R:0}" />
</rule>
<rule name="Reverse Proxy to vuefonts" stopProcessing="true">
<match url="^fonts/(.*)" />
<action type="Rewrite" url="http://localhost:8002/{R:0}" />
</rule>
<rule name="Reverse Proxy to vueimg" stopProcessing="true">
<match url="^img/(.*)" />
<action type="Rewrite" url="http://localhost:8002/{R:0}" />
</rule>
<rule name="static" stopProcessing="true">
<match url="^static(.*)" />
<action type="Rewrite" url="http://localhost:8000/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>