gpt4 book ai didi

apache - 如何在 Apache 中使用 SSL 配置多个子域?

转载 作者:太空宇宙 更新时间:2023-11-03 12:45:51 25 4
gpt4 key购买 nike

配置:

  • Debian
  • Apache2
  • 用于 *.example.com 的通配符 SSL
  • 子域:a.example.com、b.example.com。
  • 1 台专用服务器
  • 网站使用 NodeJS(ProxyPass...)

现在,我可以让 a.example.com 正常工作。但是我如何才能使 a.example.com 和 b.example.com 在同一台服务器上工作?

/etc/apache2/site-enable/a.example.com.conf
<VirtualHost *:80>
ServerName a.example.com
Redirect permanent / https://a.example.com
</VirtualHost>
<VirtualHost *:80>
ServerName www.a.example.com
Redirect permanent / https://a.example.com
</VirtualHost>
Listen 443

<VirtualHost *:443>
ServerName a.example.com
ServerAlias www.a.example.com

ProxyRequests off
LimitRequestLine 150000
LimitRequestFieldSize 150000
<Proxy *>
Order deny,allow
Allow from all
</Proxy>

<Location />
ProxyPass http://localhost:4949/
ProxyPassReverse http://localhost:4949/
</Location>

SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:!LOW:!aNULL:!eNULL

SSLCertificateFile /etc/ssl/2__.example.fr.crt
SSLCertificateKeyFile /root/XXXXXX.key
SSLCertificateChainFile /etc/ssl/1_root_bundle.crt
</VirtualHost>

更新---如果我试试这个:

/etc/apache2/site-enable/b.example.com.conf
<VirtualHost *:80>
ServerName b.example.com
Redirect permanent / https://b.example.com
</VirtualHost>
<VirtualHost *:80>
ServerName www.b.example.com
Redirect permanent / https://b.example.com
/VirtualHost>

Listen 443

<VirtualHost *:443>
ServerName b.example.com
ServerAlias www.b.example.com

ProxyRequests off
LimitRequestLine 150000
LimitRequestFieldSize 150000
<Proxy *>
Order deny,allow
Allow from all
</Proxy>

<Location />
ProxyPass http://localhost:6949/
ProxyPassReverse http://localhost:6949/
</Location>

SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:!LOW:!aNULL:!eNULL

SSLCertificateFile /etc/ssl/2__.example.fr.crt
SSLCertificateKeyFile /root/XXXXXX.key
SSLCertificateChainFile /etc/ssl/1_root_bundle.crt
</VirtualHost>

我明白了

[....] Restarting web server: apache2[Thu Jul 21 14:58:01 2016] [warn] module passenger_module is already loaded, skipping
[Thu Jul 21 14:58:01 2016] [warn] _default_ VirtualHost overlap on port 443, the first has precedence
[Thu Jul 21 14:58:01 2016] [warn] NameVirtualHost *:80 has no VirtualHosts
... waiting [Thu Jul 21 14:58:02 2016] [warn] module passenger_module is already loaded, skipping
[Thu Jul 21 14:58:02 2016] [warn] _default_ VirtualHost overlap on port 443, the first has precedence
[Thu Jul 21 14:58:02 2016] [warn] NameVirtualHost *:80 has no VirtualHosts
(98)Address already in use: make_sock: could not bind to address [::]:443

---更新

我在 b.exemple.com.conf 上删除了 Listen 443

但是现在,我有这个:

a.example.com ---> b.example.com
b.example.com ---> b.example.com

问题是当我尝试访问 a 时,我被重定向到 b

我做错了什么?

/etc/apache2/site-enable/b.example.com.conf
<VirtualHost *:80>
ServerName b.example.com
Redirect permanent / https://b.example.com
</VirtualHost>
<VirtualHost *:80>
ServerName www.b.example.com
Redirect permanent / https://b.example.com
/VirtualHost>

<VirtualHost *:443>
ServerName b.example.com
ServerAlias www.b.example.com

ProxyRequests off
LimitRequestLine 150000
LimitRequestFieldSize 150000
<Proxy *>
Order deny,allow
Allow from all
</Proxy>

<Location />
ProxyPass http://localhost:6949/
ProxyPassReverse http://localhost:6949/
</Location>

SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:!LOW:!aNULL:!eNULL

SSLCertificateFile /etc/ssl/2__.example.fr.crt
SSLCertificateKeyFile /root/XXXXXX.key
SSLCertificateChainFile /etc/ssl/1_root_bundle.crt
</VirtualHost>

-- 更新找到解决方案 :)

我终于找到了解决问题的办法,谢谢你的帮助!

<IfModule mod_ssl.c>
Listen 443
NameVirtualHost *:443
</IfModule>
<VirtualHost *:443>
ServerName www.example.fr
DocumentRoot "/var/www/html/404"

SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:!LOW:!aNULL:!eNULL

SSLCertificateFile /etc/ssl/2__.example.fr.crt
SSLCertificateKeyFile /root/XXXXX.key
SSLCertificateChainFile /etc/ssl/1_root_bundle.crt
</VirtualHost>
<VirtualHost *:80>
ServerName www.example.fr
Redirect permanent / https://a.example.fr
</VirtualHost>


<VirtualHost *:80>
ServerName a.example.fr
Redirect permanent / https://a.example.fr
</VirtualHost>
<VirtualHost *:443>
ServerAdmin admin@admin.fr
ServerName a.example.fr

ProxyRequests off
LimitRequestLine 150000
LimitRequestFieldSize 150000
<Proxy *>
Order deny,allow
Allow from all
</Proxy>

<Location />
ProxyPass http://localhost:4949/
ProxyPassReverse http://localhost:4949/
</Location>

SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:!LOW:!aNULL:!eNULL

SSLCertificateFile /etc/ssl/2__.example.fr.crt
SSLCertificateKeyFile /root/serveurA.key
SSLCertificateChainFile /etc/ssl/1_root_bundle.crt

</VirtualHost>





<VirtualHost *:80>
ServerName b.example.fr
Redirect permanent / https://b.example.fr
</VirtualHost>
<VirtualHost *:443>
ServerAdmin admin@admin.fr
ServerName b.example.fr

ProxyRequests off
LimitRequestLine 150000
LimitRequestFieldSize 150000
<Proxy *>
Order deny,allow
Allow from all
</Proxy>

<Location />
ProxyPass http://localhost:6949/
ProxyPassReverse http://localhost:6949/
</Location>

SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:!LOW:!aNULL:!eNULL

SSLCertificateFile /etc/ssl/2__.example.fr.crt
SSLCertificateKeyFile /root/serveurA.key
SSLCertificateChainFile /etc/ssl/1_root_bundle.crt

</VirtualHost>

最佳答案

更改所有子域的通配符 (*.example.com) 的虚拟主机代码,要实现此功能,您的 SSL 证书应该是支持多个子域的通配符

<virtualhost>中更改/添加两行apache httpd.confssl.conf 文件的代码

 ServerName www.example.com
ServerAlias *.example.com

例子:

a.example.com
b.example.com
WHATEVER_SUB-DOMAIN_TEXT.example.com

关于apache - 如何在 Apache 中使用 SSL 配置多个子域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38503828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com