无法将http重定向到https

时间:2017-03-17 14:56:23

标签: apache

我无法将我的http流量重定向到https,因此我的网站可以同时使用http和https访问,但我希望它只能通过https访问。位于/ var / apps / web /中的.htaccess文件如下所示:

RewriteEngine On
RewriteCond %{SERVER_PORT} !443
RewriteRule ^(/(.*))?$ https://%{HTTP_HOST}/$1 [R=301,L]

我编辑了apache2.conf并添加了以下配置:

<Directory /var/mode/cci/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
</Directory>

位于/ etc / apache2 / sites-available中的文档根目录如下所示:

<VirtualHost *:7777>
        ServerAdmin webmaster@localhost
        ServerName mydomain.co/
        DocumentRoot /var/apps/web/
        Header always append X-Frame-Options SAMEORIGIN
        Header always set X-XSS-Protection "1; mode=block"
        Header always unset Server
        Header always set X-Content-Type-Options nosniff
        <Directory />
                Options -Indexes -FollowSymLinks -MultiViews
                AllowOverride None
        </Directory>
        <Directory /var/apps/web/>
                LimitRequestBody 512000
                Options -Indexes -FollowSymLinks -MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -Indexes -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
        TraceEnable off

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<VirtualHost *:443>
        ServerAdmin webmaster@localhost
        ServerName mydomain.co/
        DocumentRoot /var/apps/web/
        Header always append X-Frame-Options SAMEORIGIN
        Header always set X-XSS-Protection "1; mode=block"
        Header always unset Server
        Header always set X-Content-Type-Options nosniff
        <Directory />
                Options -Indexes -FollowSymLinks -MultiViews
                AllowOverride None
 </Directory>
        <Directory /var/apps/web/>
                LimitRequestBody 512000
                Options -Indexes -FollowSymLinks -MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -Indexes -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>
         SSLEngine on
        SSLCertificateFile /etc/apache2/ssl/apache.crt
        SSLCertificateKeyFile /etc/apache2/ssl/apache.key

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
        TraceEnable off

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

请帮助!

0 个答案:

没有答案