Maulik Kanani
Maulik Kanani

Reputation: 652

How to add Virtual host on ec2 wiith Apache 2.4.18?

I'm trying to domain to point specific document root of EC2 instance. I've set Route 53 and and also set DNS to domain. Now domain points fine. I have also added host to host file of server. Now I would like to add following code to /etc/httpd/conf/httpd.conf. I used to do same with Apache 2.2.

NameVirtualHost *:80
<VirtualHost *:80>
        DocumentRoot /var/www/html/xyz
        ServerName xyz.com
</VirtualHost>

But When I open etc/httpd/conf/httpd.conf it seems too small file Though I have added same to etc/httpd/conf/httpd.conf and same it and restart Apache with service httpd restart.

Would anyone suggest me how can I add it?

Upvotes: 0

Views: 4538

Answers (1)

Maulik Kanani
Maulik Kanani

Reputation: 652

I added following code to at the bottom of add following code to /etc/httpd/conf/httpd.conf

<VirtualHost *:80> ServerName xyz.com RewriteEngine On #RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] DocumentRoot /var/www/html/xyz <Directory /var/www/html/xyz> DirectoryIndex index.php AllowOverride All </Directory> </VirtualHost> Save file and restart Apache as it will be effective once you restart the server with service httpd restart.

Upvotes: 2

Related Questions