在运行“本机” nginx Web服务器的Raspberry Pi上与docker一起使用Mailu

问题描述 投票:0回答:1

我在Carsten Rieger guide之后在运行Ubuntu Server 18.04.4 64位的Raspberry Pi 4上配置了Nextcloud,因此现在在Pi上已安装并运行nginx。然后,使用Mailu configuration安装了带有Docker Compose的邮件服务器。我选择标准配置,因为“本地” nginx和“ docker容器” 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个回答
0
投票

如果我正确理解您的问题,则希望将主机上的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;
    }
  }

... 

}

关于第二个问题,是的,您可以使用“让我们加密”来获取证书。既可以独立使用,也可以与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 
© www.soinside.com 2019 - 2024. All rights reserved.