【发布时间】:2017-12-21 18:36:11
【问题描述】:
我们的网络服务器上有这两个配置文件。
http:
<VirtualHost *:80>
ServerName www.example.de
ServerAlias example.de www.example.at example.at www.example.net example.net
RewriteEngine On
RewriteCond %{HTTP_HOST} off
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}
# Error page is just the index telling about the situation of not being connected
ErrorDocument 404 /index.html
</VirtualHost>
https:
<IfModule mod_ssl.c>
NameVirtualHost *:443
<VirtualHost *:443>
ServerName www.example.de
ServerAlias example.de www.example.at example.at www.example.net example.net
SSLEngine On
SSLCertificateFile /etc/letsencrypt/live/www.example.de/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.example.de/privkey.pem
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ %{REQUEST_SCHEME}://www.%{HTTP_HOST}$1 [R=301,L]
DocumentRoot /var/www/homepage/web
<Directory /var/www/homepage/web>
AllowOverride All
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
ErrorLog ${APACHE_LOG_DIR}/example-ssl.error.log
CustomLog ${APACHE_LOG_DIR}/example-ssl.access.log combined
</VirtualHost>
</IfModule>
当我尝试打开http://www.example.com 时,它会被重定向到https://www.example.com
当我尝试打开 http://example.com 或 https://example.com 时,出现错误“页面不可用”
我在网络服务器上的两个 conf 文件有什么问题? 两者都应该重定向到https://www.example.com url。
【问题讨论】:
-
不,HTTP_HOST 不会包含值
off...除非您尝试访问http://off,否则不会包含值 -
我应该在哪里添加这个 HTTP_HOST,我可以将其设置为关闭?
-
为什么不配置没有重定向的 apache 虚拟主机并从 .htaccess 文件进行重定向?
-
我想,在 Apache conf 中会更容易
-
“我应该在哪里添加这个 HTTP_HOST,我可以将其设置为关闭?” - 无处,因为这甚至没有意义。您在这里访问了错误的变量。你想检查
HTTPS变量。