更新时间:2025-07-01 00:00点击:54
语境:
我有一个域名: example.com,但我想创建一个像这样的域 api.example.com 使用它像网络服务一样。
昨晚,我有一个免费的SSL证书使用 让我们加密.
我的域名 example.com 应该打开内容 /var/www/website/.
我的域名 api.example.com 应该打开内容 /var/www/api/.
我正在寻找互联网上的一些信息,我创建了这些文件 /etc/apache2/sites-available/
<VirtualHost *:80>ServerName example.comDocumentRoot /var/www/website/LogLevel debugErrorLog ${APACHE_LOG_DIR}/example.com/error.log<Directory "/var/www/website/">Options FollowSymLinksAllowOverride None</Directory></VirtualHost><VirtualHost *:443>ServerName example.comDocumentRoot /var/www/website/LogLevel debugErrorLog ${APACHE_LOG_DIR}/example.com/error_ssl.logSSLEngine onSSLCertificateKeyFile /etc/apache2/ssl/example.com/privkey.pemSSLCertificateFile /etc/apache2/ssl/example.com/cert.pemSSLCertificateChainFile /etc/apache2/ssl/example.com/chain.pem<Directory "/var/www/website/">Options FollowSymLinksAllowOverride None</Directory></VirtualHost><VirtualHost *:80>ServerName api.example.comDocumentRoot /var/www/api/#RewriteEngine On#RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]<Directory "/var/www/api/">Options FollowSymLinksAllowOverride None</Directory></VirtualHost><VirtualHost *:443>ServerName api.example.comDocumentRoot /var/www/api/LogLevel warnErrorLog ${APACHE_LOG_DIR}/error.logSSLEngine onSSLCertificateKeyFile /etc/apache2/ssl/example.com/privkey.pemSSLCertificateFile /etc/apache2/ssl/example.com/cert.pemSSLCertificateChainFile /etc/apache2/ssl/example.com/chain.pem<Directory "/var/www/api/">Options FollowSymLinksAllowOverride None</Directory></VirtualHost>我创建了两个文件,因为我虽然我们需要分隔域,但是当我尝试输入时 example.com 我有内容 api.example.com.
和 让我们加密,我已经为两个域创建了相同的SSL证书,并且文件所在 /etc/apache2/ssl/example.com/.
我找到了解决方案!
我已经编辑过了 httpd.conf 和 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.gzNameVirtualHost *:80Listen 80NameVirtualHost *: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>
SSLStrictSNIVHostCheck on
现在我可以使用该域来网站和WebService

夏天爱出汗,“清凉馅”饺子别错过,清爽鲜美,不油腻,一口一个

卧室摆上5种花,空气清新还能睡个安稳觉,你家养过几种?

五道家常下饭荤菜!简单易做,味道鲜美,建议爱吃辣的朋友尝一尝

活着活着,就明白了,跟任何人较劲都是在消耗自己;原谅别人是你大度,放过自己才是格局

你其实已经很幸福了,吃得饱,穿得暖,没病没灾,偶尔还能享受一顿美食。拥有这样的福气,人生已是一大幸事,知足常乐

湖南这个5A级大山,实力硬核却没啥人!丹霞够野,云海够仙

最粘人的6种猫咪!喜欢和猫咪贴贴的看过来!

剩饭秒变大餐!6种炒饭做法香翻天,你家常备哪款?

散步才是普通人减肥的最好运动?

机油真的可以行驶1万5千公里再换吗?维修工:做到这3点完全可以