【问题标题】:Mailu with docker on a Raspberry Pi running a "native" nginx web serverMailu 在运行“本机”nginx Web 服务器的 Raspberry Pi 上使用 docker
【发布时间】:2020-06-29 21:43:59
【问题描述】:

我在运行 Ubuntu Server 18.04.4 64 位的 Raspberry Pi 4 上配置了 Nextcloud,遵循 Carsten Rieger guide,所以现在在 Pi 上安装并运行 nginx。然后,我使用Mailu configuration 安装了一个带有 Docker Compose 的邮件服务器。我修改了标准配置,因为“native” nginx 和“docker container” nginx 使用的端口 80 和 443 冲突,所以在容器中我使用 8080 和 8443。

我必须如何配置本机 nginx,以便当我访问我的 mail.mydomain.com 时重定向到 8080 和 8443 端口? 如何使用 Let's Encrypt 为 mail.mydomain.com 获取 HTTPS 证书?

【问题讨论】:

    标签: docker nginx configuration docker-compose port


    【解决方案1】:

    如果我理解你的问题是正确的,你喜欢使用主机上的 nginx 作为代理服务器来将流量重定向到 docker 容器。

    在主机上扩展你的 nginx.conf:

    http {
    
    ...
    
    
      # redirect http to https from your domain
      server {
          listen 80;
          server_name localhost, <your domain>, <secondary domain>;
          return 301 https://<your domain>$request_uri;
      }
    
      # simple reverse-proxy
      server {
        listen 443;
        server_name  localhost, <your domain>, <secondary domain>;
    
        ssl on;
        # if you use let's encrypt (certbot) /etc/letsencrypt/live/<your domain>/fullchain.pem
        ssl_certificate      <path to certificate>;
        # if you use let's encrypt (certbot) /etc/letsencrypt/live/<your domain>/privkey.pem
        ssl_certificate_key  <path to key>;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # don’t use SSLv3 ref: POODLE
    
        client_max_body_size 200M;
    
        # pass requests for dynamic content to rails/turbogears/zope, et al
        location / {
          proxy_pass      http://localhost:8080;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
          proxy_set_header Host $http_host;
    
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forward-Proto http;
          proxy_set_header X-Nginx-Proxy true;
    
          proxy_redirect off;
        }
      }
    
    ... 
    
    }
    

    对于您的第二个问题,是的,您可以使用 Let's Encrypt 来获取证书。无论是作为独立的还是与 nginx 插件一起使用。

    $ sudo add-apt-repository ppa:certbot/certbot
    $ sudo apt-get update
    $ sudo apt-get install python-certbot-nginx
    

    在没有 nginx 插件的情况下获取你的证书(你需要先停止 nginx,因为 certbot 使用端口 80)

    $ sudo certbot certonly --standalone -d <your domain> -d <secondary domain>
    

    使用 nginx 插件获取您的证书

    $ sudo certbot --nginx -d <your domain> -d <secondary domain>
    

    在任何情况下,您都需要在检索或更新证书后重新加载 nginx:

    $ sudo service nginx reload 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-18
      • 1970-01-01
      • 1970-01-01
      • 2020-01-21
      • 2022-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多