【发布时间】:2021-08-27 07:40:18
【问题描述】:
我已在 AWS EC2 实例上安装了我的新网站并拥有弹性 IP。我已经为我的网站启用了 HTTPS。目前,域名与网站一起加载没有任何问题,但 IP 指向 Apache 默认页面。我按照几个教程将 IP 地址指向我网站的 HTTPS 版本。但它不起作用。但是,如果我使用 https://xx.xx.xx.xx,我会收到“您的连接不是私密的”警告。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteCond %{REMOTE_ADDR} ^xx\.xx\.xx\.xx$
RewriteRule ^(.*)$ https://mynewwebsite.com/$1 [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
虚拟主机:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin admin@mynewwebsite.com
ServerName mynewwebsite.com
ServerAlias www.mynewwebsite.com
DocumentRoot /var/www/html/wordpress
ErrorLog ${APACHE_LOG_DIR}/mynewwebsite.com_error.log
CustomLog ${APACHE_LOG_DIR}/mynewwebsite.com_access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/mynewwebsite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mynewwebsite.com/privkey.pem
</VirtualHost>
</IfModule>
【问题讨论】:
-
“但 IP 指向 Apache 默认页面” - 这可能意味着,Apache 首先不知道将请求路由到哪个虚拟主机 - 并且意味着,它也不会进入您的 .htaccess 所在的目录。
-
@CBroe 只有 IP 指向默认的 apache 页面。你能帮我解决问题吗?
-
“只有 IP 指向默认的 apache 页面” - 是的,正如我所说,可能因为您的 VHost 设置仅涵盖特定的主机名.
-
@CBroe 我已经用我的主机文件更新了帖子。如您所见,我在主机文件中使用
。如何将 IP 包含到主机文件中。 -
@Praveen 您收到不安全连接错误,因为 SSL 证书名称对于 IP 地址无效。这个是正常的。但我不明白这个问题:如果用户使用 IP (xx.xx.xx.xx -> mynewwebsite.com) 访问您的网站,您是否需要重定向到 FQDN?
标签: wordpress apache .htaccess