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

Azure App Service部署Nginx/HTML容器启动失败求助

问题:Azure App Service 部署Docker Compose Nginx应用启动失败

本地运行docker-compose up完全正常,但部署到Azure App Service后访问站点显示应用错误,日志提示多容器单元启动失败。


相关配置文件

Docker Compose配置(Azure版)

version: '2.2'
services:
  loadbalancer:
    image: .../loadbalancertest
    networks:
      - mynetwork
    ports:
      - 80:8090
    tty: true
networks:
  mynetwork:
    driver: bridge

Dockerfile

FROM nginx:alpine
RUN apk update && apk upgrade && apk add bash curl && apk add openssl;
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY index.html /usr/share/nginx/html
RUN mkdir /usr/nginx
RUN openssl req -x509 -nodes -days 3650 -subj "/C=CA/ST=QC/O=Company, Inc./CN=isiGov.gov" -addext "subjectAltName=DNS:isiGov.gov" -newkey rsa:2048 -keyout /usr/nginx/ssl.key -out /usr/nginx/ssl.crt;
EXPOSE 8090

# Start Nginx
CMD ["nginx", "-g", "daemon off;"]

index.html

<!DOCTYPE html>
<html>
<head>
    <title>Hello World</title>
</head>
<body>
    <h1>Hello World</h1>
    <p>Welcome to your first HTML document!</p>
</body>
</html>

nginx.conf

error_log  ./error.log warn;

server {
    server_name _;
    listen 8090 ssl;
    underscores_in_headers on;
    ssl_certificate /usr/nginx/ssl.crt;
    ssl_certificate_key /usr/nginx/ssl.key;
    
    location /  {
        root /usr/share/nginx/html;
        index index.html index.htm;
        try_files $uri $uri/ /index.html;

    }
}
events { worker_connections 1024; }

Azure应用Docker日志

2024-07-28T15:41:39.048Z INFO  - docker run -d -p 7865:80 --name isiworkflowwizard-dev_loadbalancer_0_3e6c9a02 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=ISIWorkflowWizard-dev -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=isiworkflowwizard-dev.azurewebsites.net -e WEBSITE_INSTANCE_ID=d2fb0ec5c9f8c5efa098c8e3693f48097d07c3d7fa038e9dad975abf2e74aa53 bprassistantregistry.azurecr.io/loadbalancertest 
2024-07-28T15:41:39.048Z INFO  - Logging is not enabled for this container.
Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.
2024-07-28T15:45:29.724Z ERROR - multi-container unit was not started successfully
2024-07-28T15:45:30.706Z INFO  - Container logs from isiworkflowwizard-dev_loadbalancer_0_3e6c9a02 = 2024-07-28T15:41:40.755987733Z /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
2024-07-28T15:41:40.756020084Z /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
2024-07-28T15:41:40.759056350Z /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
2024-07-28T15:41:40.773221158Z 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
2024-07-28T15:41:41.613023846Z 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf differs from the packaged version
2024-07-28T15:41:41.614128103Z /docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
2024-07-28T15:41:41.655591651Z /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
2024-07-28T15:41:41.668644315Z /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
2024-07-28T15:41:41.677649816Z /docker-entrypoint.sh: Configuration complete; ready for start up
2024-07-28T15:41:41.701702373Z 2024/07/28 15:41:41 [notice] 1#1: using the "epoll" event method
2024-07-28T15:41:41.701743530Z 2024/07/28 15:41:41 [notice] 1#1: nginx/1.27.0
2024-07-28T15:41:41.701753168Z 2024/07/28 15:41:41 [notice] 1#1: built by gcc 13.2.1 20231014 (Alpine 13.2.1_git20231014) 
2024-07-28T15:41:41.701760772Z 2024/07/28 15:41:41 [notice] 1#1: OS: Linux 5.15.153.1-1.cm2
2024-07-28T15:41:41.701768056Z 2024/07/28 15:41:41 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 131072:131072
2024-07-28T15:41:41.703971848Z 2024/07/28 15:41:41 [notice] 1#1: start worker processes
2024-07-28T15:41:41.703997947Z 2024/07/28 15:41:41 [notice] 1#1: start worker process 29
2024-07-28T15:41:41.704007184Z 2024/07/28 15:41:41 [notice] 1#1: start worker process 30

2024-07-28T15:45:34.594Z INFO  - Stopping site isiworkflowwizard-dev because it failed during startup.

问题分析与修复方案

从日志可见Nginx容器本身已成功启动,但Azure判定启动失败,核心问题是端口映射不匹配+SSL配置冲突:

问题点

  1. Azure启动容器时自动映射端口7865:80,但你的Nginx监听8090端口,且Docker Compose配置的80:8090和Azure的端口逻辑不兼容。
  2. Azure App Service的SSL终止在前端负载均衡层,容器内无需处理SSL,强制启用SSL会导致连接失败。

修复步骤

1. 修改nginx.conf,改为监听80端口(HTTP)

error_log  ./error.log warn;

server {
    server_name _;
    listen 80; # 移除SSL配置,监听80端口
    underscores_in_headers on;
    
    location /  {
        root /usr/share/nginx/html;
        index index.html index.htm;
        try_files $uri $uri/ /index.html;

    }
}
events { worker_connections 1024; }

2. 更新Dockerfile的EXPOSE端口与SSL相关步骤

  • 将EXPOSE 8090改为EXPOSE 80
  • 删除SSL证书生成的冗余步骤:
# 移除以下两行
RUN mkdir /usr/nginx
RUN openssl req -x509 -nodes -days 3650 -subj "/C=CA/ST=QC/O=Company, Inc./CN=isiGov.gov" -addext "subjectAltName=DNS:isiGov.gov" -newkey rsa:2048 -keyout /usr/nginx/ssl.key -out /usr/nginx/ssl.crt;

3. 调整Docker Compose端口映射

改为映射80端口,匹配容器内Nginx的监听端口:

version: '2.2'
services:
  loadbalancer:
    image: .../loadbalancertest
    networks:
      - mynetwork
    ports:
      - "80:80" # 修正为80端口映射
    tty: true
networks:
  mynetwork:
    driver: bridge

4. 重新构建并部署

修改完成后,重新构建镜像推送到容器注册表,再重新部署到Azure App Service即可。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 05:44:51