gpt4 book ai didi

apache - 如何使用相同的 SSL 证书配置多个 - Apache

转载 作者:太空宇宙 更新时间:2023-11-03 14:41:44 31 4
gpt4 key购买 nike

上下文:

我有一个域:example.com,但我想创建一个像 api.example.com 这样的域,以便像 Web 服务一样使用它。

昨晚,我使用 Let's Encrypt 获得了一个免费的 SSL 证书。

我的域 example.com 应该打开 /var/www/website/ 中的内容。

我的域 api.example.com 应该打开 /var/www/api/ 中的内容。

我在网上找了一些资料,在/etc/apache2/sites-available/中创建了这些文件

/etc/apache2/sites-available/example.com

<VirtualHost *:80>

ServerName example.com
DocumentRoot /var/www/website/

LogLevel debug
ErrorLog ${APACHE_LOG_DIR}/example.com/error.log

<Directory "/var/www/website/">
Options FollowSymLinks
AllowOverride None
</Directory>

</VirtualHost>

<VirtualHost *:443>

ServerName example.com
DocumentRoot /var/www/website/

LogLevel debug
ErrorLog ${APACHE_LOG_DIR}/example.com/error_ssl.log

SSLEngine on
SSLCertificateKeyFile /etc/apache2/ssl/example.com/privkey.pem
SSLCertificateFile /etc/apache2/ssl/example.com/cert.pem
SSLCertificateChainFile /etc/apache2/ssl/example.com/chain.pem

<Directory "/var/www/website/">
Options FollowSymLinks
AllowOverride None
</Directory>

</VirtualHost>

/etc/apache2/sites-available/api.example.com

<VirtualHost *:80>

ServerName api.example.com
DocumentRoot /var/www/api/

#RewriteEngine On
#RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]

<Directory "/var/www/api/">
Options FollowSymLinks
AllowOverride None
</Directory>

</VirtualHost>

<VirtualHost *:443>

ServerName api.example.com
DocumentRoot /var/www/api/

LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/error.log

SSLEngine on
SSLCertificateKeyFile /etc/apache2/ssl/example.com/privkey.pem
SSLCertificateFile /etc/apache2/ssl/example.com/cert.pem
SSLCertificateChainFile /etc/apache2/ssl/example.com/chain.pem

<Directory "/var/www/api/">
Options FollowSymLinks
AllowOverride None
</Directory>

</VirtualHost>

我创建了两个文件,因为虽然我们需要分隔域,但是当我尝试输入 example.com 时,我已经在 api.example 中获得了内容。 com.

使用 Let's encrypt,我为两个域创建了相同的 SSL 证书,文件位于 /etc/apache2/ssl/example.com/

最佳答案

我找到了解决方案!

我已经编辑了 httpd.confports.conf

/etc/apache2/ports.conf

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz

NameVirtualHost *:80
Listen 80

NameVirtualHost *:443

<IfModule mod_ssl.c>
# If you add NameVirtualHost *:443 here, you will also have to change
# the VirtualHost statement in /etc/apache2/sites-available/default-ssl
# to <VirtualHost *:443>
# Server Name Indication for SSL named virtual hosts is currently not
# supported by MSIE on Windows XP.
Listen 443
</IfModule>

<IfModule mod_gnutls.c>
Listen 443
</IfModule>

/etc/apache2/httpd.conf

SSLStrictSNIVHostCheck on

现在我可以将域名用于网站和网络服务

关于apache - 如何使用相同的 SSL 证书配置多个 <virtualhost> - Apache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42580329/

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