使用 ssl 在 apache 中配置多个站点

使用 ssl 在 apache 中配置多个站点

我需要在 Apache 中保护两个不同的站点。其中一个站点应该只是在端口 8069 上运行的另一台服务器的代理。

现在一个(原生包含在apache中)使用SSL运行:

<VirtualHost *:443>
      ServerName 192.168.1.20
      SSLEngine on
      SSLCertificateFile /etc/ssl/erp/oeserver.crt
      SSLCertificateKeyFile /etc/ssl/erp/oeserver.key
      DocumentRoot /var/www/cloud
      ServerPath /cloud/
      #CustomLog /var/www/logs/ssl-access_log combined
      #ErrorLog /var/www/logs/ssl-error_log
</VirtualHost>

另一个没有运行,甚至没有注册。当我尝试访问它时,我收到异常(ssl_error_rx_record_too_long):

<VirtualHost *:443>

ServerName 192.168.1.20
ServerPath /erp/

SSLEngine on
SSLCertificateFile /etc/ssl/erp/oeserver.crt
SSLCertificateKeyFile /etc/ssl/erp/oeserver.key

ProxyRequests Off
ProxyPreserveHost On

<Proxy *>
Order deny,allow
Allow from all
</Proxy>

ProxyVia On
ProxyPass / http://127.0.0.1:8069/
ProxyPassReverse / http://127.0.0.1:8069
RewriteEngine on
RewriteRule ^/(.*) http://127.0.0.1:8069/$1 [P]


RequestHeader set "X-Forwarded-Proto" "https"

SetEnv proxy-nokeepalive 1
</VirtualHost>

我希望的是以下配置:

192.168.1.20        ->> unsecured local path to website
192.168.1.20/cloud/ ->> secured local documentpath from cloud
192.168.1.20/erp/   ->> secured proxy on port 80 for http://192.168.1.20:8069

这怎么可能?这可能吗?也许 cloud.192.168.1.20 和 erp.192.168.1.20 更好?!

谢谢 ============= 编辑 ============================ apache2ctl -S -M: *:443 是 NameVirtualHost 默认服务器 myserver(/etc/apache2/conf.d/cloud.conf:1) 端口 443 namevhost myserver(/etc/apache2/conf.d/cloud.conf:1) *:80 是 NameVirtualHost 默认服务器 myserver(/etc/apache2/sites-enabled/default:1) 端口 80 namevhost myserver(/etc/apache2/sites-enabled/default:1)

默认:

<VirtualHost *:80>
  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

修改后的(当前)cloud.conf:

<VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile /etc/ssl/openerp/oeserver.crt
    SSLCertificateKeyFile /etc/ssl/openerp/oeserver.key
    DocumentRoot /var/www/
    RewriteCond {REQUEST_URI} ^/cloud$
    RewriteEngine on
    RewriteRule /(.*) http://127.0.0.1:8069/$1 [P]
    RequestHeader set "X-Forwarded-Proto" "https"
    SetEnv proxy-nokeepalive 1
</VirtualHost>

答案1

你不能有

<VirtualHost *:443>
      ServerName 192.168.1.20
      SSLEngine on

2次,因为apache只会绑定到一个虚拟主机。

为什么不将 /locations/ 都包含在一个配置中?

<VirtualHost *:443>
      ServerName 192.168.1.20
      SSLEngine on
      SSLCertificateFile /etc/ssl/erp/oeserver.crt
      SSLCertificateKeyFile /etc/ssl/erp/oeserver.key
      DocumentRoot /var/www/cloud
      <Directory /var/www/cloud>
          blah
      </Directory>

      # erp-config
      # ... proxy_config ....
      ProxyPass /erp http://127.0.0.1:8069/
      proxyPassReverse /erp http://127.0.0.1:8069/

</VirtualHost>

編輯2

另一种方法是 2 个单独的<VirtualHosts>配置,基于名称(一个 IP,SNI 必须可用)或基于 IP(每个主机一个 IP,通常始终有效)

相关内容