在 apache red hat 中将 http 重定向到 https
Posted
技术标签:
【中文标题】在 apache red hat 中将 http 重定向到 https【英文标题】:Redirect http to https in apache red hat 【发布时间】:2018-11-11 12:55:08 【问题描述】:我正在尝试将 http 重定向到 https VirtualHost 这是我添加到 httpd-vhosts.conf 的代码
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/html/dummy-host.example.com
ServerName apache1.poc
Redirect / https://apache1.poc
ServerAlias www.apache1.poc
ErrorLog /var/log/httpd/dummy-host.example.com-error_log
CustomLog /var/log/httpd/dummy-host.example.com-access_log common
</VirtualHost>
<VirtualHost *:443>
ServerName apache1.poc
DocumentRoot /var/www/html/dummy-host.example.com
SSLEngine On
# etc...
</VirtualHost>
但 httpd.service 没有重新启动,我得到以下状态
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2018-06-01 13:20:17 WET; 5min ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 4813 ExecStop=/bin/kill -WINCH $MAINPID (code=exited, status=1/FAILURE)
Process: 4811 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
Main PID: 4811 (code=exited, status=1/FAILURE)
Jun 01 13:20:16 Apache1.POC systemd[1]: Starting The Apache HTTP Server...
Jun 01 13:20:16 Apache1.POC systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Jun 01 13:20:17 Apache1.POC kill[4813]: kill: cannot find process ""
Jun 01 13:20:17 Apache1.POC systemd[1]: httpd.service: control process exited, code=exited status=1
Jun 01 13:20:17 Apache1.POC systemd[1]: Failed to start The Apache HTTP Server.
Jun 01 13:20:17 Apache1.POC systemd[1]: Unit httpd.service entered failed state.
Jun 01 13:20:17 Apache1.POC systemd[1]: httpd.service failed.
【问题讨论】:
错误日志中有什么内容? 谢谢我找到了解决办法 【参考方案1】:我找到了解决方案: 在 httpd-vhosts.conf 文件中我必须只添加:
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/html/dummy-host.example.com
ServerName apache1.poc
Redirect / https://apache1.poc
ServerAlias www.apache1.poc
ErrorLog /var/log/httpd/dummy-host.example.com-error_log
CustomLog /var/log/httpd/dummy-host.example.com-access_log common
</VirtualHost>
然后我必须去 ssl.conf 文件并添加:
# General setup for the virtual host, inherited from global configuration
DocumentRoot "/var/www/html/apache1.poc"
ServerName apache1.poc:443
【讨论】:
以上是关于在 apache red hat 中将 http 重定向到 https的主要内容,如果未能解决你的问题,请参考以下文章
Linux下Apache/2.2.3(Red Hat)Server at localhost Port 80怎么回事
配置 httpd.conf 以在 Apache Red Hat Linux 上添加新站点
Red Hat Linux6.8 中的安装ActiveMQ 5.14.1
mod_wsgi (3.4-14) / Apache 2.4.12 / Red Hat (6.7) / Django 1.8.2 在负载下挂起