You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Microsoft IIS Server部署Angular集成.NET应用时SSL参数配置失效问题问询

Why Your Angular/.NET IIS HTTPS Setup Isn't Working (And How to Fix It)

Hey there, let's clear up the confusion first—your local ng serve --ssl=true setup works because that's configuring the Angular development server to use SSL. But when you deploy to IIS, you're serving static build artifacts (from ng build), and that package.json start script has no impact on the deployed environment. IIS is now the one responsible for handling HTTPS, not Angular's dev server. That's why your SSL parameter feels like it "isn't working" in the pipeline.

Let's walk through the key steps you're missing to get HTTPS working on IIS:

1. Bind a Valid SSL Certificate to Your IIS Site

Angular's dev server generates a self-signed certificate automatically for local testing, but IIS requires a valid certificate (either from a trusted CA like Let's Encrypt, your organization's internal CA, or a self-signed one for testing). Here's how to set it up:

  • Open IIS Manager, navigate to your site, and click Bindings in the right-hand pane.
  • Click Add, select HTTPS as the type, choose your SSL certificate from the dropdown, set the port to 443 (standard HTTPS port), and save.
  • If you don't have a certificate, you can create a self-signed one via IIS (Server Certificates > Create Self-Signed Certificate) or use a tool like Certbot for Let's Encrypt.

2. Verify Port 443 is Open and Unblocked

The HTTPS timeout you're seeing is likely due to the port being blocked:

  • Check if another service is using port 443 on the server with the command: netstat -ano | findstr :443
  • Make sure your server's firewall (Windows Firewall or cloud security groups if it's a cloud server) has an inbound rule allowing traffic on port 443.

3. Adjust Angular Build Configuration (No SSL Parameter Needed)

When building for deployment, the --ssl flag does nothing—you just need to ensure your app doesn't hardcode HTTP URLs (which would cause mixed-content errors once HTTPS is enabled):

  • Use relative paths for API calls (e.g., /api/endpoint instead of http://your-server/api/endpoint) so the app uses the same protocol as the page.
  • If you must use absolute URLs, update them to use https:// instead of http://.

4. Optional: Enforce HTTPS with IIS URL Rewrite

To make sure all users are redirected to HTTPS, add a URL rewrite rule to your web.config (this assumes you have the IIS URL Rewrite module installed):

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Force HTTPS" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

Quick Recap

Your local npm run start uses Angular's dev server, so the --ssl=true flag controls that server's SSL. Once deployed to IIS, SSL is entirely an IIS configuration task—you need a bound certificate, open port 443, and correct app resource paths to avoid mixed content.

内容的提问来源于stack exchange,提问作者user1563232

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 08:48:12