大网数据广告活动
服务器运维问答

Apache on debian don't redirect http to https correctly

· 52CE 我爱测

Debian 11 config file: /etc/apache2/sites-enabled/000-default.conf <VirtualHost *:80> RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} ServerName zabbix.example.ru </VirtualHost> <Virt…

问题原文

原帖链接 · Ishayahu · CC BY-SA 4.0

Debian 11

config file: /etc/apache2/sites-enabled/000-default.conf

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

</VirtualHost>
<VirtualHost *:443>
    ServerName zabbix.example.ru
    DocumentRoot "/usr/share/zabbix/"
</VirtualHost>

If I open in brouser zabbix.example.ru it will be open by https. But if I open manualy http://zabbix.example.ru it doesn't redirect to https

The same setting (as I understand) perfectly forks for me on FreeBSD, but it looks like on Debian I should make something other

/usr/sbin/apachectl -S

VirtualHost configuration:
*:80                   zabbix.lasil.ru (/etc/apache2/sites-enabled/000-default.conf:1)
*:443                  zabbix.lasil.ru (/etc/apache2/sites-enabled/000-default.conf:9)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

UPD: I was a little wrong about problem. Not only there is no redirect, but such an error is also issued

Bad Request
Your browser sent a request that this server could not understand.
Reason: You're speaking plain HTTP to an SSL-enabled server port.
Instead use the HTTPS scheme to access this URL, please.
Apache/2.4.54 (Debian) Server at zabbix.example.ru Port 80

已采纳解答

原帖链接 · Ishayahu · CC BY-SA 4.0

Thank's to all.

After reading comments I understand that site configuration (where was enabled SSL) (that was in /etc/apache2/conf-enabled/ folder) wasn't limited to any VirtualHost, so it was enabled to all server, not only to port 443

I moved it to VirtualHost on port 433 and problem was solved

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2023-05-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。