使用NGINX + ANGULAR + Docker生产SSL

问题描述 投票:0回答:1

一如既往,感谢您的提示和建议。

我有一个角度应用程序,我想与Nginx一起部署。我正在使用certbot创建证书,并且工作正常。这意味着我能够访问我的域。但是该域给我一个错误,因为它找不到所有生产文件。这是我的有角dockerfile:

#stage 1
FROM node:10.16.0 as node
WORKDIR /app
COPY . /app/
RUN npm install
ARG configuration=production
RUN npm run build -- --prod --configuration=$configuration

#stage 2
FROM nginx:alpine
COPY --from=node /app/dist/angular-SPA /usr/share/nginx/html
COPY ./nginx-config.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

这是我的nginx-config.conf:

server {
  listen 80;
  location / {
    root /usr/share/nginx/html;
    index index.html index.htm;
    try_files $uri $uri/ /index.html =404;
  }
}

并且我有一个文件夹,其中包含docker-compose.yml和nginx.conf。我不确定这是否是个好习惯。但这就是我之前的开发人员的工作方式。

在nginx文件夹中,这是docker-compose.yml

web:
  image: nginx
  volumes:
   - ./:/usr/share/nginx/html
   - ./nginx.conf:/etc/nginx/conf.d/nginx.conf 
   - /etc/letsencrypt:/root/letsencrypt
  ports:
   - "80:80"
   - "443:443"
  command: /bin/bash -c "nginx -g 'daemon off;'"

这是nginx的nginx配置。

server {
    listen              80;
    server_name example.com;
    location ^~ /.well-known/acme-challenge/ {
        allow all;
        #default_type "text/plain";
    }
    location / {
        return 301 https://example.com;
    }
}
server {
    listen              443 ssl;
    server_name         example.com;
    ssl_certificate     /root/letsencrypt/live/example.com-0001/fullchain.pem;
    ssl_certificate_key /root/letsencrypt/live/example-0001/privkey.pem;
    location ^~ /.well-known/acme-challenge/ {
        allow all;
        default_type "text/plain";
    }
    location = / {
        proxy_pass        http://PRIVATE_IP_OF_AWS_INSTANCE:9090/index.html;
    }
}

PRIVATE_IP_OF_AWS_INSTANCE是我的AWS EC2实例的私有ip。我的角形容器在端口9090:80上运行。

这是我尝试访问example.com时遇到的错误:

example.com/:15 GEThttps://example.com/runtime-es2015.858f8dd898b75fe86926.jsnet :: ERR_ABORTED 404(未找到)example.com/:12 GEThttps://example.com/styles.45c31720860b353d5204.cssnet :: ERR_ABORTED 404(未找到)example.com/:15 GEThttps://example.com/polyfills-es2015.5728f680576ca47e99fe.jsnet :: ERR_ABORTED 404(未找到)favicon.ico:1 GEThttps://example.com/favicon.ico404(未找到)

请帮助,欢迎提供任何建议或提示。

angular docker nginx deployment production
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.