Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Docker并希望使用NGINX反向代理HTTP-Grafana从HTTP到HTTPS_Docker_Nginx_Grafana_Nginx Reverse Proxy - Fatal编程技术网

使用Docker并希望使用NGINX反向代理HTTP-Grafana从HTTP到HTTPS

使用Docker并希望使用NGINX反向代理HTTP-Grafana从HTTP到HTTPS,docker,nginx,grafana,nginx-reverse-proxy,Docker,Nginx,Grafana,Nginx Reverse Proxy,我使用的是Docker,NGINX和Grafana有单独的容器。我试图最终将浏览器连接为HTTPS,并能够查看Grafana站点。我需要3件事情来实现这一点,但无论我用谷歌搜索了多少,我都无法让它工作 将所有前往NGINX的HTTP流量切换为HTTPS 使用NGINX反向代理将HTTPS流量发送到Grafana容器 这些同样在Docker容器中。我想使用Docker网络进行NGINX和Grafana之间的通信,容器的名称是3000端口上的Grafana 我目前的NGINX default.con

我使用的是Docker,NGINX和Grafana有单独的容器。我试图最终将浏览器连接为HTTPS,并能够查看Grafana站点。我需要3件事情来实现这一点,但无论我用谷歌搜索了多少,我都无法让它工作

  • 将所有前往NGINX的HTTP流量切换为HTTPS
  • 使用NGINX反向代理将HTTPS流量发送到Grafana容器
  • 这些同样在Docker容器中。我想使用Docker网络进行NGINX和Grafana之间的通信,容器的名称是3000端口上的Grafana

    我目前的NGINX default.conf为:

        server {
            listen 80;
            listen [::]:80;
            server_name localhost;
            return 301 https://$host$request_uri;
        }
    
        server {
            listen 443 ssl;
            server_name localhost;
            ssl_certificate                 /etc/ssl/certs/nginx-selfsigned.crt; # 
         or /etc/ssl/openhab.crt
            ssl_certificate_key             /etc/ssl/private/nginx-selfsigned.key; 
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_ciphers HIGH:!aNULL:!MD5;
            location / {
                proxy_pass http://grafana/;
            }
         }
    
    它不会把它送给格拉法纳。它将从HTTPS切换到HTTP,但在那里停止。我正在使用另一台具有已编辑主机文件的计算机,mmig.com将连接到此计算机的IP地址

    我可以看到去,然后就停在那里了。它不会带我去格拉法纳

    当它运行时,我得到下面的错误

    nginx        | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
    nginx        | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
    nginx        | 10-listen-on-ipv6-by-default.sh: error: can not modify /etc/nginx/conf.d/default.conf (read-only file system?)
    nginx        | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
    nginx        | /docker-entrypoint.sh: Configuration complete; ready for start up
    nginx        | 2020/09/11 17:26:59 [emerg] 1#1: host not found in upstream "grafana" in /etc/nginx/conf.d/default.conf:16
    nginx        | nginx: [emerg] host not found in upstream "grafana" in /etc/nginx/conf.d/default.conf:16```
    
    
    Docker-compose
    ``` grafana:
        image: grafana/grafana
        container_name: grafana
        restart: always
        depends_on:
         - influxdb
         - nginx
        ports:
         - "3000:3000"
        networks:
         - monitoring
        volumes:
          - grafana-db:/var/lib/grafana
          - grafana-log:/var/log/grafana
          - grafana-conf:/etc/grafana
          - ./certs:/etc/ssl:ro
      nginx:
       image: nginx
       container_name: nginx
       restart: always
       ports:
        - "80:80"
        - "443:443"
       networks:
        - monitoring
       volumes:
        - ./nginx/etc/nginx:/etc/nginx:ro
        - ./certs:/etc/ssl:ro
    networks:
      monitoring:
    
    nginx.conf

    ```
        user  nginx;
        worker_processes  1;
    
        error_log  /var/log/nginx/error.log warn;
        pid        /var/run/nginx.pid;
    
    
        events {
            worker_connections  1024;
        }
    
    
        http {
          include       /etc/nginx/mime.types;
          default_type  application/octet-stream;
    
          log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        access_log  /var/log/nginx/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        keepalive_timeout  65;
    
        #gzip  on;
    
        upstream grafana {
            server grafana:3000;
        }
    
        include /etc/nginx/conf.d/*.conf;
        }
    ```
    
    这是我当前的NGINX default.conf文件,其中HTTP转到HTTPS,但它甚至不会转到默认的NGINX主页。我还不明白为什么会这样

    ```   server {
            listen       80;
            server_name  localhost;
            return       301 https://$host$request_uri;
        }
        server {
            listen       443 ssl;
            server_name  localhost;
        # SSL
            ssl_certificate                 /etc/ssl/certs/nginx-selfsigned.crt; # 
         or /etc/ssl/openhab.crt
            ssl_certificate_key             /etc/ssl/private/nginx-selfsigned.key;
    
         location / {
                root   /usr/share/nginx/html;
            index  index.html index.htm;
            }
         }
    ```
    

    这看起来像是因为我的主机在Virtualbox VM上,并且在NAT后面,因为另一个VM正在使用网桥网络,所以代理权限被破坏了。我用这个虚拟机安装了另一台计算机,它能够使用网桥网络,工作正常。

    主机名“grafana”似乎无法解析。这两个容器是网桥网络的一部分吗?您是使用docker compose来管理这两个容器,还是仅使用单个docker命令?是的,它们是docker中监控网络的一部分。我也在使用docker compose。这是Docker Compose与这两个容器相关的输出。您可以发布Docker-Compose.yml吗?这可能是相关的。好吧,我刚才也在我的问题中添加了这个。如果我没有HTTPS的部分,那就把它交给Grafana吧。当我在其中添加HTTPS时,发生了一些事情。所以HTTP-to-HTTPS有效,但对Grafana无效,HTTP-to-Grafana反向代理有效,但对HTTP-HTTPS-Grafana无效。更多信息可能会有所帮助。我将上游命令移动到nginx.conf文件中。它仍然没有看到它
    2020/09/11 18:05:20[emerg]1#1:host未在/etc/nginx/nginx.conf:32 nginx中的上游“grafana:3000”中找到[emerg]host未在/etc/nginx/nginx.conf:32中的上游“grafana:3000”中找到主机