Контейнер Docker nginx https отказывается работать - PullRequest
0 голосов
/ 08 февраля 2019

у нас есть веб-сайт, мы должны быть только https.это прекрасно работает, если мы возьмем код для запуска https.

Это угловое 7 приложение, работающее на nginx в докере.Он будет размещен в Azure.

Файл Docker:

### STAGE 1: Build ###

# We label our stage as 'builder'
FROM node:8-alpine as builder

COPY package*.json ./

RUN npm set progress=false && npm config set depth 0 && npm cache clean --force

## Storing node modules on a separate layer will prevent unnecessary npm installs at each build
RUN npm i && mkdir /ng-app && cp -R ./node_modules ./ng-app

WORKDIR /ng-app

COPY . .

 ## Build the angular app in production mode and store the artifacts in dist 
 folder
 RUN $(npm bin)/ng build --prod --build-optimizer


 ### STAGE 2: Setup ###

FROM nginx:1.13.3-alpine
COPY /certs /etc/nginx/
## Copy our default nginx config
COPY nginx/default.conf /etc/nginx/conf.d/
COPY nginx.conf /etc/nginx/nginx.conf

## Remove default nginx website
RUN rm -rf /usr/share/nginx/html/*

## From 'builder' stage copy over the artifacts in dist folder to default 
nginx public folder
COPY --from=builder /ng-app/dist /usr/share/nginx/html

CMD ["nginx", "-g", "daemon off;"]

Файл default.conf:

server {

  listen 80;

  sendfile on;

  default_type application/octet-stream;

  gzip on;
  gzip_http_version 1.1;
  gzip_disable      "MSIE [1-6]\.";
  gzip_min_length   256;
  gzip_vary         on;
  gzip_proxied      expired no-cache no-store private auth;
  gzip_types        text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
  gzip_comp_level   9;

  root /usr/share/nginx/html;

  location / {
    try_files $uri $uri/ /index.html =404;
  }
}

и, наконец, наш файл nginx.conf:

# nginx Configuration File
# http://wiki.nginx.org/Configuration

# Run as a less privileged user for security reasons.
user nginx;

worker_processes auto;

events {
  worker_connections 1024;
}

pid        /var/run/nginx.pid;

http {
    server {
        listen 80;
        listen 443 ssl;
        server_name digitise.co.za www.digitise.co.za;

        ssl_certificate           /etc/nginx/ssl.crt;
        ssl_certificate_key       /etc/nginx/ssl.key;

        location / {
            proxy_pass         http://127.0.0.1;
            proxy_redirect     off;
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Host $server_name;
       }

       # force https-redirects
       if ($scheme = http) {
           return 301 https://$server_name$request_uri;
       }
   }
}

Мы работаем в среде Windows.Мы все еще новички в nginx, так как мы всегда использовали iis, но при переходе на azure нам нужно использовать nginx.

мы строим образ, выполняя docker build -t digitise ., затем запускаем образ, выполняя docker run -p 3000:80 -p 3001:443 digitise

на моем компьютере разработчика, нажимающем http://localhost:3001, перенаправляет меня на https://localhost., нажимающем https://localhost:3001 не имеет никакого эффекта.это даже не попадает на сервер.нажатие http://localhost:3000 возвращает неверный запрос, простой HTTP-запрос был отправлен на порт https

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...