How can I create subdomains on Amazon EC2?
Is adding virtual host in httpd.conf is enough.. or any other changes also needs to be done?
Thanks
Depends on your server software. But as you mention httpd.conf, chances are good that you run Apache on a Linux distribution. If that's the case then yes, adding a virtual host is enough. Here is one way of doing it:
Purchase a domain. If you have one, skip this, we'll take example.com for this example.
Find the external IP or DNS for your EC2 instance. You probably want to associate an Elastic IP to your instance, otherwise the IP of your instance will change on reboots.
Create a DNS record for your domain, for instance a CNAME record to point to your Elastic IP/DNS name:
subdomain.example.com => ec2-xx-xxx-xxx-xxx.eu-west-1.compute.amazonaws.com
Make sure your httpd.conf contains a line to allow virtual hosts:
NameVirtualHost *:80
Create a virtual host directive:
httpd.conf:
<VirtualHost *:80>
ServerName subdomain.example.com
ServerAdmin webmaster#subdomain.example.com
DocumentRoot /var/www/example.com/subdomain
<Directory /var/www/example.com/subdomain>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/subdomain.example.com.error.log
LogLevel warn
CustomLog /var/log/apache2/subdomain.example.com.access.log combined
</VirtualHost>
6. Restart Apache
/etc/init.d/apache2 restart
Related
I recently made some projects on raspberry pi with linux Debian Jessie, and I am interested in porting forward websites hosted on raspberry pi to a domain I owned.
From what I learned, it is possible to make each individual website on raspberry link with configured port according to apache , for example /home/pi/html/website01 -> port 11235 website02 -> 11236 so that I can browse the websites in private network. However, the domain I have is managed by godaddy, they provide the Chain without port, so that I can't redirect one of my third level domain(ex dashboard.domain.com to my dynamic dns hostname xx.dtdns.net with the port.
Is there any possible way or idea to get it work? I am lack of knowledge of nameserver, but I have an idea that using vpn or vps to map users to my private network instead of godaddy domain manager. I have alreay built the openvpn with cert and pptp vpn on my raspberrypi. Is it possible or what's next step?
Thanks, please give me some idea.
One solution would be to use Virtual Hosting in Apache on your Raspberry. Install Apache2 on PI with:
apt-get install apache2
Create a new conf file in /etc/apache2/sites-available or use an existing one. Add the ports for different site directories:
<VirtualHost *:11235>
DocumentRoot /var/www/w1
<Directory /var/www/w1>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:11236>
DocumentRoot /var/www/w2
<Directory /var/www/w2>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
and then set Apache tolisten on the ports in the /etc/apache2/ports.conf file:
Listen 11235
Listen 11236
Restart the Apache service. You should now be able to browse both ports using the same ip address. If your ip was 111.111.111.111 then w1 directory on 111.111.111.111:11235 and 111.111.111.111:11236.
If your domain is pointing to a IP, you can use different hostnames without making change to DNS. If you domain was mydomain.com, you could instead add new virtual host names with:
<VirtualHost *:80>
ServerName w1.mydomain.com
DocumentRoot /var/www/w1
<Directory /var/www/w1>
Options +Includes -Indexes +FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName w2.mydomain.com
DocumentRoot /var/www/w2
<Directory /var/www/w2>
Options +Includes -Indexes +FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
I'm trying to set up a subdomain for on a client's web server. It's a CentOS server running Apache. So say the website is "example.com". I'm trying to create "bugs.example.com".
So far, I've added to the vhost.conf file the subdomain info:
<VirtualHost *:80>
ServerName bugs.example.com
ServerAlias bugs.example.com
DocumentRoot /var/www/www.bugs.example.com
<Directory "/var/www/www.bugs.example.com">
AllowOverride ALL
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I've added the server's IP address and the subdomain to /etc/hosts:
111.222.333.444 bugs.example.com
I've created the directory for the website files, and an index page at:
/var/www/www.bugs.example.com/index.html
Sadly, I still get a "Server not found" error when I go to bug.example.com. What am I missing here? The example.com domain name is registered through GoDaddy.com. Is there something that needs to be done there?
I've this configuration for my virtual host and runs with real domains. For testing purpose I need create same virtual host with non real domain (i.e. domain10). Considerated that the browser check the name of domain of virtual host, I think using something like 127.0.0.1. But I've no idea to realize this.
<VirtualHost *:80>
ServerAdmin info#domain10.org
ServerName domain10.org
ServerAlias domain10.org
DirectoryIndex index.html index.htm index.php
DocumentRoot /home/domain10.org/
<Directory /home/domain10.org/>
Options -Includes -Indexes -FollowSymLinks -ExecCGI +MultiViews
AllowOverride none
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
You can use the /etc/hosts file for this purpose. There should already be a line in it beginning with 127.0.0.1. Just add domain10.org to the list of hosts that resolves to this address.
For example, if the existing line is:
127.0.0.1 localhost localhost.localdomain
Just extend it to:
127.0.0.1 localhost localhost.localdomain domain10.org
Then (on this machine only) domain10.org will resolve to 127.0.0.1. If you are testing on the same machine, you can enter http://domain10.org/ in your browser to reach your local web server.
If you need to reach this host over the Internet, then a different approach is needed. Look for a line for the external IP address of the server in its /etc/hosts file and modify it similar to the above instructions. If such a line does not exist, add one.
On the client machine, do the same (using /etc/hosts for a Linux box or %WINDIR%\system32\drivers\etc\hosts for a Windows box). You should then be able to reach the server from the client using this name.
I have recently just set up a RHEL based server running two domains. However, I am having difficulty hitting both domains from the browser. My config is:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName domainA.com
ServerAlias domainA.com *.domainA.com
DocumentRoot /home/domainA/public_html
<Directory "/home/domainA/public_html">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName domainB.com
ServerAlias domainB.com *.domainB.com
DocumentRoot /home/domainB/public_html
<Directory "/home/domainB/public_html">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
The problem is when I navigate to domainA.com I hit the correct Virtualhost (which is fine), however when I navigate to domainB.com it displays the Apache Test page.
Edit
I have a Firewall between the webserver and the web. I tested the rules governing Domain A and Domain B.
Domain A reaches target and a status 200 is returned.
Domain B reaches target and a status 403 (permission denied) is returned
What you need to do is take a look at sites-enabled and sites-available.
Here's the first entry when Googling: http://www.debian-administration.org/articles/412
Looks reasonable and should help you integrate that.
The problem is that you need separate entries for all the sites you want to run on this apache2. Simple entries in your config file don't do it. Only the first works, the rest is more or less ignored. Creating separate entries with sites-enabled and sites-available is the way to go here.
I set Centos 6.3 up on a Rackspace box, using a static IP address (not a FQDN). I will be setting up virtual hosts on this box, and it seems to be working fine, but when I restart the HTTPD server, I get an error message "could not reliably determine the server's fully qualified domain name, using xx.xxx.xx.xx for ServerName" (xx.xxx.xx.xx is the static IP address for the server).
My /etc/hosts has the following in it:
27.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
xx.xxx.xx.xx name-used-for-rackspace
name-used-for-racspace is a name (not a FQDN) I used when I created the server (you have to enter a name).
I assume that I may not have to change anything in /etc/hosts, but what do I put in httpd.conf? right now, I have the following in that file:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName localhost
<Directory /var/www/html>
allow from all
Options +Indexes
</Directory>
</VirtualHost>
I also tried setting ServerName to xx.xxx.xx.xx, but I got the same error message.
This error is because you are not using a FQDN. It should not affect the operation of the webserver.
To get rid of the message on startup you'd need to configure your hosts file with the correct domain and IP address. Your httpd.conf should also use the same name (where you have localhost specified).
As long as your server is starting and you don't plan on assigning a domain to your webserver, this error can be ignored.
Example virtual host with FQDN:
<VirtualHost *:80>
ServerName www.domain.net
ServerAlias domain.net *.domain.net
ServerAdmin administrator#domain.net
DocumentRoot "/home/domain/htdocs"
<Directory "/home/domain/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
CustomLog "/home/domain/logs/access-www.log" common
ErrorLog "/home/domain/logs/error-www.log"
<IfModule mpm_peruser_module>
ServerEnvironment apache apache
</IfModule>
</VirtualHost>
Example hosts file:
127.0.0.1 localhost localhost.localdomain gentoo1
x.x.x.x gentoo1.domain.net
You need to configure the network connection with your static IP, see reference below. Otherwise, your web server is working, but it's not accessible externally.
https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/sec-Configuring_IPv4_Settings.html
Then put the static IP in the httpd.conf after server name.