docker中的nginx如何禁用http重定向到https

时间:2016-04-05 18:20:00

标签: curl nginx docker

我正在尝试使用docker容器在digitalocean中部署meteor应用程序。我已经在两个web dockers和一个nginx docker中完成了设置应用程序。我分叉this image repo来构建docker。你可以在lib目录下看到nginx config。这里nginx配置了SSL并请求web docker。我遇到了一些问题,要生成ipaddress的SSL证书。应用程序正在开发中,因此计划立即删除SSL。所以改了Nginx配置。

daemon off;
error_log /dev/stdout notice;
worker_processes  1;

events {
    worker_connections  4096;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    upstream site{
      server backend1:80;
      server backend2:80;
    }

    sendfile        on;
    keepalive_timeout  65;

    gzip  on;

    server {
        listen              80 default_server;
        server_name         mup-ssl; //tried mup-ssl; and _;
        client_max_body_size 10M;


        location / {
          proxy_pass http://site/;
          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-Proto $scheme;

          proxy_http_version 1.1;
          proxy_set_header    Upgrade           $http_upgrade;
          proxy_set_header    Connection        "upgrade";

          #
          # Specific for comet or long running HTTP requests, don't buffer up the
          # response from origin servers but send them directly to the client.
          #
          proxy_buffering     off;

          #
          # Bump the timeout's so someting sensible so our connections don't
          # disconnect automatically. We've set it to 12 hours.
          #
          proxy_connect_timeout 43200000;
          proxy_read_timeout    43200000;
          proxy_send_timeout    43200000;
        }
    }
}

问题在于,当我在浏览器中点击http://xxx.xxx.xxx.xx.xx时,它会重定向到https://xxx.xxx.xxx.xx.xx。我该如何禁用https?重定向。

卷曲响应:

curl -i http://xxx.xxx.xx.xx
HTTP/1.1 302 Moved Temporarily
Server: nginx/1.8.0
Date: Tue, 05 Apr 2016 18:09:11 GMT
Transfer-Encoding: chunked
Connection: keep-alive
Location: https://xxx.xxx.xx.xx/

curl -i https://xxx.xxx.xx.xx/
curl: (7) Failed to connect to xxx.xxx.xx.xx port 443: Connection refused

1 个答案:

答案 0 :(得分:0)

在docker-compose中,在环境中添加:HTTPS_METHOD = noredirect。 喜欢这个

service:
    container_name: name
    restart: always
    environment:
      - HTTPS_METHOD=noredirect
    env_file:
      - .env