wordpress - 将 IP 地址重定向到域 (Apache)
问题描述
我已经在 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 而不是我的服务器 FQDN 替换 ServerName 时,问题解决了。我假设这种方法只适用于我已经添加的 /etc/hosts 中的服务器和域。
<VirtualHost *:80>
ServerAdmin admin@mynewwebsite.com
ServerName xx.xx.xx.xx <------------------- IP
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
RewriteEngine on
RewriteCond %{SERVER_NAME} =mynewwebsite.com [OR]
RewriteCond %{SERVER_NAME} =www.mynewwebsite.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin@mynewwebsite.com
ServerName mynewwebsite.com <------------------- Domain
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
RewriteEngine on
RewriteCond %{SERVER_NAME} =mynewwebsite.com [OR]
RewriteCond %{SERVER_NAME} =www.mynewwebsite.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
推荐阅读
- javascript - 从远程 XML 设置单元格高度 % 的样式元素
- php - 循环遍历 PHP 中的对象数组
- mongodb - brew install mongodb vs mongodb-community@4.0
- android - Android 文本和滚动视图——为什么不呈现 HTML 格式的文本?
- python - 如何优化速度以计算 3D 数组中沿 Z 轴的平均值?Cython vs Numpy
- haproxy - Haproxy 不适用于 8081,但适用于 8080
- python - 在单批次中对数据集中的每个图像进行 N 次采样
- c++ - 如何在 Qt Creator 中包含 boost 标头库
- pandas - 使用 pandas 舍入/格式化小数,从 csv 文件的列中读取
- c++ - 如何从字符串中获取浮点值?