sengar19
sengar19

Reputation: 45

How redirect Amazon EC2 Machine url to a domain?

I know it might sound unconventional, as it's normally other way around. But because of a unique situation I'm facing this issue. The issue is that I want to redirect ec2-xx-xx-xxx-xxx.ap-southeast-1.compute.amazonaws.com/xyz (development url) to https://xyz.example.com (production url - a sub-domain). The config for other way around is working well. I went through apache docs and tried some settings, but it's not taking effect. Below are the config and server details.

#ssl setting

<VirtualHost *:443>
 ServerAdmin [email protected]
 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>

Server details: Ubuntu 14.04.2 LTS, Apache2

'A' record setting is already done and working.

I have limited knowledge in server configuration. I did some research but still not able to figure out the problem in the config.

Please advice me where I'm doing wrong.

Best Regards

Ranjeet Sengar

Upvotes: 0

Views: 955

Answers (1)

Vikash
Vikash

Reputation: 459

First of all why you are using Public DNS Name of EC2 instead of creating your own some.example.com and creates a A record with Elastic IP of EC2

Second, in the above config, you are using server name as

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

Try changing the ServerName and restart the apache.

sudo service apache2 restart

Upvotes: 2

Related Questions