iis - 尝试从 Azure Devops 创建 URL 重写规则时出错
问题描述
我正在使用 azure devops 步骤尝试使用 Manage IIS 任务在 IIS 中创建 https 重定向规则。
我正在使用以下“其他 appcmd.exe 命令”
set config -section:system.webServer/rewrite/rules /+"[name='http_redirect',enabled='True']" /commit:apphost
set config -section:system.webServer/rewrite/rules.[name='http_redirect'] /match.url:"(.*)" /match.ignoreCase:true /commit:apphost
set config -section:system.webServer/rewrite/rules.[name='http_redirect'].conditions/add /+"[input='{HTTPS}',pattern='off']" /commit:apphost
set config -section:system.webServer/rewrite/rules.[name='http_redirect'].action /+"[type='Redirect',url='https://{HOST_NAME}/{R:1}',redirectType='Found']" /commit:apphost
似乎第一个命令在创建空白规则时运行,但第二个命令尝试通过名称http_redirect查找规则失败
解决方案
您可以使用以下命令全局设置 URL 重写:
appcmd.exe set config -section:system.webServer/rewrite/globalRules /+"[name='http_redirect']" /commit:apphost
appcmd.exe set config -section:system.webServer/rewrite/globalRules /[name='http_redirect'].match.url:"(.*)" /commit:apphost
appcmd.exe set config -section:system.webServer/rewrite/globalRules /+"[name='http_redirect'].conditions.[input='{HTTPS}',pattern='off']" /commit:apphost
appcmd.exe set config -section:system.webServer/rewrite/globalRules /[name='http_redirect'].action.type:"Redirect" /[name='http_redirect'].action.url:"https://{HTTP_HOST}/{R:1}" /[name='http_redirect'].action.redirectType:"Found" /commit:apphost
注意:不要使用 {HOST_NAME},使用 {HTTP_HOST}。
要申请特定站点,请使用以下命令:
appcmd.exe set config "aspsite" -section:system.webServer/rewrite/rules /+"[name='http_redirect']" /commit:apphost
appcmd.exe set config "aspsite" -section:system.webServer/rewrite/rules /[name='http_redirect'].match.url:"(.*)" /commit:apphost
appcmd.exe set config "aspsite" -section:system.webServer/rewrite/rules /+"[name='http_redirect'].conditions.[input='{HTTPS}',pattern='off']" /commit:apphost
appcmd.exe set config "aspsite" -section:system.webServer/rewrite/rules /[name='http_redirect'].action.type:"Redirect" /[name='http_redirect'].action.url:"https://{HOST_NAME}/{R:1}" /[name='http_redirect'].action.redirectType:"Found" /commit:apphost
编辑:power-shell命令添加规则:
import-module webAdministration
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.webserver/rewrite/GlobalRules" -name "." -value @{name='HTTP to HTTPS Redirect'; patternSyntax='ECMAScript'; stopProcessing='True'}
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.webserver/rewrite/GlobalRules/rule[@name='HTTP to HTTPS Redirect']/match" -name url -value "(.*)"
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.webserver/rewrite/GlobalRules/rule[@name='HTTP to HTTPS Redirect']/conditions" -name "." -value @{input="{HTTPS}"; pattern='^OFF$'}
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.webServer/rewrite/globalRules/rule[@name='HTTP to HTTPS Redirect']/action" -name "type" -value "Redirect"
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.webServer/rewrite/globalRules/rule[@name='HTTP to HTTPS Redirect']/action" -name "url" -value "https://{HTTP_HOST}/{R:1}"
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.webServer/rewrite/globalRules/rule[@name='HTTP to HTTPS Redirect']/action" -name "redirectType" -value "SeeOther"
推荐阅读
- sql - 在 sqlalchemy 中设置自引用多对多关系
- tensorflow - 如何仅在主块对角线上为协方差矩阵 RBF 加上噪声在 GPflow 中编写自定义内核?
- azure - 此 Azure DevOps 存储库中的宏是否会导致我的部署管道失败?
- python - Word2Vec 对象不可下标
- import - 如何生成从自定义模块下载文件的链接?PrestaShop 1.7
- sql - 序列容器
- uno-platform - Uno 平台底座面板
- performance - VMware - “ethernetX.pnicFeatures”和“ethernetX.ctxPerDev”参数有什么区别?
- javascript - 如何在 html 页面的任何位置显示动态文本
- node.js - WebSocket 连接到 'ws://X.XXX.XXX.XXX:5858/socket.io/?EIO=3&transport=websocket' 失败: