在apache red hat中将http重定向到https

时间:2018-06-01 11:30:17

标签: apache http https redhat httpd.conf

我正在尝试将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 个答案:

答案 0 :(得分:0)

我找到了解决方案: 在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