繁体   English   中英

使用 SSL 证书和多个域设置 apache 反向代理

[英]Set up an apache reverse proxy with SSL certs and multiple domains

我需要帮助将 Apache 配置为具有 https 和多个域的反向代理,这样www.myfirstdomain.comwww.myseconddomain.com都指向xxxx ,而服务器将选择性地转发到,比如说, xxxx:2400myfirstdomain.com , http), xxxx:2401 ( myfirstdomain.com , https), xxxx :2600 ( myseconddomain.com , http) 和xxxx:2601 ( mysecondomain.com , https)。

我尝试了很多选择,但最终我被卡住了,因为我每周颁发超过 5 个证书(更新),而且我无法让它工作。

myfirstdomain.comwww.myfirstdomain.com (http 和 https)配置如下:

/etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:2400/
    ProxyPassReverse / http://127.0.0.1:2400/
</VirtualHost>

<VirtualHost *:443>
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:2401/
    ProxyPassReverse / http://127.0.0.1:2401/
</VirtualHost>

<VirtualHost *:2400>
    ServerName myfirstdomain.com
    ServerAlias www.myfirstdomain.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/myfirstdomain/public
    <Directory /var/www/html/myfirstdomain/public>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =myfirstdomain.com
    RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

    RewriteCond %{SERVER_NAME} =www.myfirstdomain.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:2401>
    ServerName myfirstdomain.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/myfirstdomain/public
    <Directory /var/www/html/myfirstdomain/public>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
    </Directory>

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =myfirstdomain.com
    RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

然后我用certbot --apache为 www 和非 www 生成了证书,我有这个文件:

/etc/apache2/sites-available/000-default-le-ssl.conf

<IfModule mod_ssl.c>
    <VirtualHost *:443>
        ProxyPreserveHost On
        ProxyPass / http://127.0.0.1:2401/
        ProxyPassReverse / http://127.0.0.1:2401/
    </VirtualHost>

    <VirtualHost *:2401>
        ServerName myfirstdomain.com
        ServerAlias www.myfirstdomain.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/myfirstdomain/public
        <Directory /var/www/html/myfirstdomain/public>
                Options Indexes FollowSymLinks
                AllowOverride All
                Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        RewriteEngine on
        # Some rewrite rules in this file were disabled on your HTTPS site,
        # because they have the potential to create redirection loops.

        #     RewriteCond %{SERVER_NAME} =myfirstdomain.com
        #     RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

        #     RewriteCond %{SERVER_NAME} =www.myfirstdomain.com
        #     RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]


        SSLCertificateFile /etc/letsencrypt/live/www.myfirstdomain.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/www.myfirstdomain.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
    </VirtualHost>

我也尝试重新生成 HTTPS 证书,但它不起作用。 我该怎么做?

首先,请记住 Apache 侦听一系列端口,例如 80 和 443。

虚拟主机使用相同的端口(80 和 443),Apache 使用您使用的域名选择正确的文件夹。

例如, myfirstdomain.com可以显示 /var/www/html/myfirstdomain/public,但是如果 apache 侦听端口 80,它永远不会匹配 *:2400 的规则。

我还没有尝试过,但是您可以将 ProxyPass 和 ProxyPassReverse 放在每个虚拟主机中,并将端口保留为 :80 或 :443。

当您调用myfirstdomain.com:80 时,apache 上的规则匹配并且它执行代理到另一台服务器。

看到这个答案

LetsEncrypt 创建一个可以从 Internet 访问的 ACME 质询(带有随机字符串的文件)。 认证服务器搜索该文件,如果存在则发布证书; 如果没有,它会抛出一个错误。

我不记得文件的正确路径,但您必须验证:

  • 你能从互联网上访问“myfistdomain.com”吗?
  • 外部服务器可以访问“myfistdomain.com”吗? (检查路由器的 dns 名称和端口转发
  • 你能打开 ACME 挑战文件吗?
  • 服务器可以打开 ACME 挑战文件吗?

在某些 Plesk 安装中,无法访问 acme 文件,因为 Plesk 添加了一些自动规则。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM