Apache
1 前言
我们经常配置Nginx的强跳(重写),由于笔者使用的http服务器是Apache,所以需要实践如何实现Apache强制HTTPS协议(强跳)。
2 最佳实践
2.1 环境的配置
本章以“limesurvey”的Apache服务器环境为例进行强跳配置,如果你不熟悉Apache服务器环境,请参考以下链接,
https://www.cmdschool.org/archives/5120
2.2 配置重写
2.2.1 开启重写模块
vim /etc/httpd/httpd.conf
将如下行的注解删除,使该行生效,
LoadModule rewrite_module modules/mod_rewrite.so
另外,如果以上模块没有启用,后面的配置会收到以下报错,
AH00526: Syntax error on line 4 of /etc/httpd/conf.d/limesurvey_80.conf: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
2.2.2 配置重写规则
<VirtualHost *:80> [...] RewriteEngine on RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^/?(.*)$ https://%{SERVER_NAME}/$1 [L,R] </VirtualHost> [...]
注:“[…]”代表省略的配置
2.2.3 检查配置的语法
httpd -t
2.2.4 配置重写规则
systemctl reload httpd
参阅文档
===================
https://serverfault.com/questions/920603/apache-error-on-suse-invalid-command-rewriteengine-perhaps-misspelled
没有评论