如何将 Amazon EC2 Machine url 重定向到域?

How redirect Amazon EC2 Machine url to a domain?

我知道这听起来可能不合常规,因为它通常是相反的。但是由于特殊情况,我面临着这个问题。问题是我想重定向 ec2-xx-xx-xxx-xxx.ap-southeast-1.compute.amazonaws.com/xyz (开发 url) 到 https://xyz.example.com(生产 url - 子域)。其他方式的配置运行良好。我浏览了 apache 文档并尝试了一些设置,但它没有生效。以下是配置和服务器详细信息。

#ssl setting

<VirtualHost *:443>
 ServerAdmin webmaster@example.com
 ServerName www.xyz.example.com
 ServerAlias xyz.example.com
 DocumentRoot /www/html/example
 SSLEngine on
 SSLCertificateFile /etc/apache2/ssl-cert/example.crt
 SSLCertificateKeyFile /etc/apache2/ssl-cert/example.key
 ErrorLog ${APACHE_LOG_DIR}/error.log
 CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

#redirection setting

<VirtualHost *:80>
 ServerAdmin webmaster@localhost
 ServerName ec2-xx-xx-xxx-xxx.ap-southeast-1.compute.amazonaws.com/xyz
 Redirect permanent / https://xyz.example.com/
 ErrorLog ${APACHE_LOG_DIR}/error.log
 CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

服务器详细信息: Ubuntu 14.04.2 LTS, Apache2

'A' 记录设置已经完成并正在运行。

我对服务器配置的了解有限。我做了一些研究,但仍然无法找出配置中的问题。

哪里做错了请指教

此致

兰吉特森加

首先,为什么您使用 Public EC2 的 DNS 名称而不是创建您自己的 some.example.com 并使用 EC2

的弹性 IP 创建 A 记录

其次,在上面的配置中,您使用的服务器名称为

www.xyz.example.com which should be xyz.example.com

尝试更改 ServerName 并重新启动 apache。

sudo service apache2 restart