google compute engine cloud dns access issue - webpage not available - apache

Instead of negative votes, how about telling my why . . .
I have set up a web server and uploaded some webpages on a LAMP stack. I am able to access via IP address. I set up my domain host to point to cloud dns. I enabled the cloud DNA api. My issue is that the domain is not loading the site, just returns "This webpage is not available / DNS lookup failed" I have read and tried a lot of different options. No Luck. Additional information:
sudo apache2ctl -S returns:
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server lamp-6kvi.c.united-yeti-790.internal (/etc/apache2/sites-enabled/lamp-server:1)
port 80 namevhost lamp-6kvi.c.united-yeti-790.internal (/etc/apache2/sites-enabled/lamp-server:1)
port 80 namevhost example.com (/etc/apache2/sites-enabled/lamp-server:28)
port 80 namevhost example.com (/etc/apache2/sites-enabled/example.com:1)
Syntax OK
The config file /etc/apache2/sites-available/example.com reads:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/websitedirectory
<Directory /var/www/websitedirectory/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/apache2/mysite-error.log
CustomLog /var/log/apache2/mysite-access.log common
cloud dns managed-zone list returns:
[
{
"creationTime": "2014-12-14T15:40:29.066Z",
"description": "",
"dnsName": "example.com.",
"id": "2608871832699155245",
"kind": "dns#managedZone",
"name": "exampledns",
"nameServers": [
"ns-cloud-d1.googledomains.com.",
"ns-cloud-d2.googledomains.com.",
"ns-cloud-d3.googledomains.com.",
"ns-cloud-d4.googledomains.com."
]
}]
I have not tried deleting the lamp-server, default or commenting out the other files . . . Please help.

To expand on your own answer, (by using web console) in general you should:
Go to your GCE Console, and
select your project.
Create the zone: In the left menu, go to Networking->Cloud DNS, then "Create Zone". Set the domain (example.com) and a name of your choice there. Once you create the zone, you will be taken to the record list of the zone.
Find the NameServer registers (the NS register type): You should see something like: ns-cloud-c1.googledomains.com, ns-cloud-c2.googledomains.com...
Set up these name servers with your Domain Registrar to make the domain accessible: go to the Registrar where this domain belongs to (NetworkSolutions/GoDaddy/Any Other), and configure the Name Servers (NS) for your domain. Set up the 4 you found in the previous step (don't just use the ones in my example, they're different for every zone you create).
Add the records you need to your zone: Go back to your GCE Console, to the Zone you just created in step 2. Click on "Add Record Set". In your case, what you need is a CNAME record: type "www" in DNS NAME, pick "CNAME" from RESOURCE RECORD TYPE, then type "example.com." as the CANONICAL NAME (notice the . at the end). Then click "Done".
You should now resolve both, example.com and www.example.com to the same IP. You also need to keep:
ServerName example.com
ServerAlias www.example.com
in your virtual host apache configuration.
Hope it helps clarify.

got it working - found out that you need to "add record set" type a for both www.example.com and example.com while pointing the ip to your server. set up virtual hosts like my question but without the section.
wish somebody would confirm that this was the proper way. anyways, added 4 more domains using the same method to the same server. :-D

Related

Apache same domain multi virtual host

I'm currently trying to set my Apache configuration.
I have one IP (ex: 10.10.10.10) and one domain (ex: www.mydomain.com).
This server is currently hosting 2 sites and each site has his own Apache Instance with his own conf and php.ini :
/appli/projects/project1/apache_2.4/conf/project1.conf => Site 1
/appli/projects/project2/apache_2.4/conf/project2.conf => Site 2
project1.conf is set like that (same with 443 for SSL) :
<VirtualHost 10.10.10.10:80>
DocumentRoot /appli/projects/project1/apache_2.4/htdocs/project1folder/
ServerName mydomain.com
</virtualHost>
project2.conf is set like that (same with 453 for SSL) :
<VirtualHost 10.10.10.10:90>
DocumentRoot /appli/projects/project2/apache_2.4/htdocs/project2folder/
ServerName mydomain.com
</virtualHost>
So when I am connecting to "mydomain.com" I am going to "Site 1" but I have to hit mydomain.com:453 for accessing to "Site 2" which is not really good...
I would like to have something like that :
mydomain.com/site1 => "Site 1" (or site1.mydomain.com)
mydomain.com/site2 => "Site 2" (or site2.mydomain.com)
And I would like to keep the mydomain.com hitting the "Site 1".
Unfortunatly, because each site has his own instance of Apache, I have no idea how to set them.
Last but not the Least I would like to know if it's possible to share PHP (Apache) SESSION accross the multi Apache Instance or if I have to use COOKIES accross the domain to share informations between sites.
I don't know if it's really clear, just ask if you need more informations.
Thanks you in advance.
My recommendation is this:
File structure:
htdocs/
site1
...files...
site2
...files...
Apache vhost:
<VirtualHost 10.10.10.10:80>
DocumentRoot /appli/projects/project1/apache_2.4/htdocs/
ServerName example.com
</virtualHost>
...and then do the same thing for the SSL-vhost.
Now you can use http://example.com/site1 and http://example.com/site2 and the same for https.
If you start using different ports (anything other than the defaults 80 and 443, you need to explicitly write the port names to be able to access the sites, or set up a reverse proxy (adds extra complexity with no real gain).
You can even define specific rules for site1 and site2 in your vhost.
Config per site:
<VirtualHost 10.10.10.10:80>
DocumentRoot /appli/projects/project1/apache_2.4/htdocs/
ServerName example.com
<Directory /appli/projects/project1/apache_2.4/htdocs/site1/>
# Some specific vhost config...
</Directory>
<Directory /appli/projects/project1/apache_2.4/htdocs/site2/>
# Some specific vhost config...
</Directory>
</virtualHost>
If you want different sub domains like: site1.example.com and site2.example.com, then just do different vhosts that point to the folders directly, still using port 80 for http and port 443 for https.
Just remember that you then need to have a multi-domain-certificate or a wildcard certificate for https (since they are two different hostnames). Or you could install Let's Encrypt.

How to host multiple domains and subdomains on single AWS EC2 instance

I am trying to set up 2 domains (domain1.com and domain2.com) with a few subdomains (app.domain1.com) in AWS and run them on single instance (Amazon Linux, PHP, MySQL).
I have set up 3 hosted zones in AWS Route53 with following configurations.
Hosted zone 1:
domain1.com
Type A
52.108.XX.YY
Hosted Zone 2
domain2.com
Type A
52.108.XX.YY
Hosted Zone 3
app.domain1.com
Type A
52.108.XX.YY
Additionally, I have added following code to the http.conf file in VirtualHost tag.
<VirtualHost *:80>
ServerName domain1.com
DocumentRoot "/var/www/html/domain1"
ErrorLog "logs/domain1-error_log"
CustomLog "logs/domain1-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerName domain2.com
DocumentRoot "/var/www/html/domain2"
ErrorLog "logs/domain2-error_log"
CustomLog "logs/domain2-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerName app.domain1.com
DocumentRoot "/var/www/html/app"
ErrorLog "logs/app.domain1-error_log"
CustomLog "logs/app.domain1-access_log" common
</VirtualHost>
However, only domain1.com and domain2.com are getting resolved. When I visit app.domain1.com, it gives me a "can't find server" error. Please help how to setup the subdomain - is there problem in Hosted Zone setup or httpd.conf?
Ok, so after about 2 hours of reading up various sites and tinkering, I am all set. Here is how to do this.
Basically, you should not have more than 1 hosted zone (HZ) per domain name, otherwise things are really going to be bad. If you have more than 1 HZ for a domain name, please delete the one that was created for the subdomain.
Each HZ will have 4 records -
Following two records are created by default. Do not edit/delete them.
NS - This is the name server record. If AWS Route53 is not your registrar, use ns-servernumber.awsdns-number.com. and other three (4 total) records to change name servers for your registrar.
SOA - Let this record be. DO NOT TOUCH THIS.
Create following two Record Set (blue button).
A - Leave Name blank. Select A-IPv4 address for Type. In Value enter the IP address for your Elastic Load Balancer or EC2 instance.
CNAME - Add * (asterisks/wildcard) in the name field. Select CNAME from the drop down for Type In Value enter the domain name.
Now create the http.conf file and structure virtual hosts like I have in the question.
Things should work now :)
You can follow the tutorial on this link: http://brianshim.com/webtricks/host-multiple-sites-amazon-ec2/
A common error, according to the link, is:
Did it work? If not, here is one possible cause. There might be
another configuration file interfering with this one. Check for
another .conf file in /etc/httpd/conf.d. Often your primary
httpd.conf will include another .conf file in this directory. Make
sure it doesn’t have some Virtual Host settings which are interfering
with yours.
After you set the configurations, you should run:
sudo service httpd restart
This can be done installing Apache HTTP Server on AWS-EC2 instance and configuring VirtualHost for each DNS or Sub-DNS as suggested by an Amazonian
For brevity read this thread discussion, this official example and techrepublic post.
Hope this helped!

IP of Web server stays in URL instead of showing Domain Name

So lets say I have the Domain Name "www.example.com" and have a "http-redirect" to server "1.1.1.1" where apache2 is running on Ubuntu 14.04 Server amd64.
I have all my web files on the server and they are working perfect.
What is not working right is the URL. Instead of "www.example.com/sites.php" if have "1.1.1.1/sites.php". How can I fix this?
What I did so far:
Disabled the default Virtual Host and created a new one:
<VirtualHost *:80>
ServerAdmin bla
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www
ErrorLog ...
CustomLog ...
</VirtualHost>
(It's typed, since I can't copy from my console..)
I tried to enter in the /etc/hosts
1.1.1.1 www.example.com
Thanks for any help
As discussed in comments, the reason that you see IP address in your browser is that http-redirect is pointing directly to to IP address, there's no domain name to display. Redirect just tells browser to go elsewhere and browser then fetches website from supplied URL, same as if you'd click on a link. If you redirect URL to 1.1.1.1/sites.php than that is what you will see in browser.

Creating subdomain on Amazon EC2 does not works

I want to create a subdomain from a real, living site which I will call example.com. The subdomain has to be named subdomain.example.com. Everything is running on a Amazon EC2 instance.
I just can't access the subdomain.example.com, when trying to access this URL, the browser shows the usual "Server not found" message.
I followed the next steps (includes steps from other StackOverflow answers):
1.-Acquired the domain example.com at GoDaddy.
2.-Linked correctly the example.com website to the real server, so the main site works fine.
3.-Went to the Amazon EC2 Console and created a EIP (Elastic IP)
4.-Went to Route53 and added a new Hosted Zone just like this article says (http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/CreatingNewSubdomain.html)
So that at I can see the subdomain.example.com Hosted Zone, and inside it there is a A Record that points to my Elastic IP.
5.-Went to the server and checked that the line "NameVirtualHost *:80" is there.
6.-Created a Virtual Host directive like the next one:
<VirtualHost *:80>
ServerName subdomain.example.com
ServerAdmin webmaster#subdomain.example.com
DocumentRoot /opt/bitnami/frameworks/codeigniter/htdocs
<Directory /opt/bitnami/frameworks/codeigniter/htdocs>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/subdomain.example.com.log
LogLevel warn
CustomLog /var/log/apache2/subdomain.example.com.access.log combined
</VirtualHost>
7.- Restarted the apache server
However, as stated at the start of the post, I can't ping or access the website.
What step could I be missing?
Are there chances that the change hasn't been propagraget yet? One day after the subdomain creation I'm still unable to access the website.
Ok, thanks to #Sergey and #datasage, the updated step list:
4.1- Go to your GoDaddy account (or your alternate provider) and add the 4 addresses obtained from Route 53 Hosted Zones, these addresses are under the label "Delegation Set".
4.2- Wait for about an hour until the changes are done (in my case it worked instantly for some reason)
Here is an useful article about these steps: http://blog.sefindustries.com/redirect-a-subdomain-to-route-53-from-godaddy/
Check subdomain.example.com, if record exists in DNS or propagated well:
Ask you default "home" DNS server
dig -t A subdomain.example.com
Ask google dns
dig -t A subdomain.example.com #8.8.8.8
Ask your authorized DNS server
dig -t A subdomain.example.com #your.ns.server
In case of windows use nslookup
or
Use internet service (for example digweb)

Why should we create A DNS record for subdomains when we can do it via httpd.conf?

I want to implement a blog in my site with usernames as subdomains like user1.domain.com.
I've read bunch of articles that was mentioned to create an A record like below in DNS:
*.domain.com A 127.0.0.1 ;OR you site ip address
Then use .htaccess to redirect requests from subdomains to a folder in your server.
But I find another approach that was said to just modify your httpd.conf as below:
<VirtualHost *:80>
DocumentRoot /abs/path/to/webroot
ServerName domainname.com
ServerAlias *.domainname.com
<Directory /abs/path/to/webroot>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Then retrieve subdomains via $_SERVER['HTTP_HOST'].
The question is why should someone use htaccess and put pressure on apache and create A DNS record when we can do a simple thing like ServerAlias *.domainname.com in httpd.conf?
I appreciate in advance for your views.
You need to setup both a wildcard DNS record and configure a server alias in httpd.conf to enable the hosting of arbitrary sub domains. They configure completely different things.
Add the wildcard DNS records is what allows clients to determine the IP address of your sub domain. With the wildcard DNS record about user1.domain.com will resolve to 127.0.0.1. If you do not have a DNS record no user1.domain.com will not be a valid name and it will not resolve to an IP address. the DNS record is to allow clients to connect to your server.
The httpd.conf configuration is local to your Apache server. It does not affect clients. The line ServerAlias *.domainname.com will configure Apache to tell it to process the arbitrary sub domains. Client's will not be directly affected by this setting.
You have added the ServerAlias, but for your computer to find that user1.domain.com and user2.domain.com should resolve to 127.0.0.1, you need to update your HOSTS file or DNS Table.
The configuration you have written is for Apache Server for handling the redirects when the user requests the domain. So, essentially, either you need a Dynamic HOSTS file or a service which resolves *.domain.com to your 127.0.0.1 server.
Hope this helps. :)