NGINX https代理传递给Gunicorn http导致混合内容错误

时间:2019-06-20 16:40:04

标签: docker nginx gunicorn

我只有一个主机在Docker容器中运行NGINX和Gunicorn。我使用NGINX将请求代理到使用Gunicorn公开的API。当我运行每个容器并导航到网站终结点时,我在nginx.conf中设置的Chrome会通知我混合内容错误,并且该请求被阻止。

我已经为我的nginx.conf文件使用了几种配置版本,无法获取任何版本来解决此混合内容错误。

我的nginx.conf是:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    root /usr/share/nginx/html;
    index index.html
    server_name example.com;

    listen 443 ssl; # managed by Certbot

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    ssl_buffer_size 8k;

    ssl_dhparam /etc/ssl/certs/dhparam-2048.pem;

    ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
    ssl_prefer_server_ciphers on;

    ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;

    ssl_ecdh_curve secp384r1;
    ssl_session_tickets off;

    # Redirect non-https traffic to https
    if ($scheme != "https") {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    location /login {
      proxy_set_header        Host $host;
      proxy_redirect off;
      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 https;
      proxy_pass          http://1.2.3.4:8000/login;
    }

}

我的Gunicorn命令是:

gunicorn --workers 4 --timeout 3600 --graceful-timeout 3600 --bind=0.0.0.0:8000 hserve:__hug_wsgi__"

当我使用上述Gunicorn命令部署API容器时,我可以使用Postman成功向端点发出请求。

我的目标是能够通过API容器(http)向Web应用程序(https)提供数据,而不会出现混合内容错误。

0 个答案:

没有答案