How to point HostGator domain to EC2 AWS - amazon-ec2

We have an existing domain name
(ex. webdev.com)
located in hostgator and we have a server in AWS. We wanted to use the domain name that we bought from hostgator
(webdev.com)
in our AWS server.
What we did was, in hostgator we created a DNS (project1.webdev.com) and the address is pointing to our AWS server(ex 150.12.1.0). In our AWS, we deploy the project1 under port 4000.
Now if we access the
project1.webdev.com
we end up to the default apache page. How could we route it to our port 4000 so that everytime we access project1.webdev.com it pointed to our
150.12.1.0:4000
project.
here is our virtual host config:
<VirtualHost *:4000>
ServerName project1.webdev.com
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "/var/www/html/project1/web"
<Directory "/var/www/html/project1/web">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/4000-error_log
CustomLog ${APACHE_LOG_DIR}/4000-access_log common
We have looked for several information but we did not find any possible solution. Looking forward for your help.
Thanks

You're confusing DNS, which has to do with IP addressing, with ports, which have nothing to do with DNS. DNS only deals with converting between human-readable names and IP addresses. DNS does not provide any sort of provision to perform a task like "when a user wants to make an HTTP request use port 4000 instead of port 80".
If your service is listening on port 4000 but you're using the HTTP protocol (which always uses port 80 by default) then you will need to deal with this in one of the following ways:
Require all URL's to explicitly specify port 4000, for example: http://project1.webdev.com:4000
Change your VirtualHost definition to listen on port 80 instead of 4000
Add a new VirtualHost definition in Apache for port 80 that proxies all requests to port 4000

Sharing you the solution we made. Thanks to #Bruce for helping us out. As what he suggested in the comments above, we will create a virtual host porting to 80(which is the default of apache). Then we will route the port 80 to our specific project.
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerName project1.webdev.com
ServerAdmin webmaster#localhost
DocumentRoot "/var/www/html/project1/web"
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/project1-error.log
CustomLog ${APACHE_LOG_DIR}/project1-access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
If you have multiple DNS just create another instance of port 80 and route to the project.
Make sure that the Domain name in HostGator matches with the ServerName you created in the virtual host.

Related

Alias in virtual host using xamp in Laravel 5.6 project

I created a virtual host in xampp for my Laravel 5.6 project.
I did this way:
I added 127.0.0.1 project.com in the hosts file in
C:\Windows\System32\drivers\etc
I changed the port 80 to 8003 in the httpd.conf file in C:\xampp\apache\conf (I changed everything from 80 to 8003 in this file)
I added this:
<VirtualHost *:8003>
DocumentRoot "C:/xampp/htdocs/project/public"
ServerName project.com
</VirtualHost>
in the httpd-vhosts.conf in C:\xampp\apache\conf\extra
I would like to use an alias because I do not want to use the url with the number port at the of the url. I just can access with this url: http://project.com:8003.
I want to enter to my project with the url like this: http://project.com
If you don't want to specify the port, you'll have to use port 80, as it's the standard for the http:// scheme. The browser doesn't magically know on what port a given service is running nor it scans all of them.
Also, the .dev tld is also a real domain and will most likely cause problems.

I cann't call my localhost by ip address

I am trying to call my xampp localhost from another computer's browser, I have changed host file at C:\Windows\System32\Drivers\etc by appending (192.168.1.105 localhost) at the end this file and save it and then restart computer, but I could not call my localhost from another computer.
Thanks
You need to access port forwarding in your router and forward port 80 only as TCP. Also, the host file code should look something like YOUR IP YOUR IP and not YOUR IP localhost. Furthermore, you need to edit httpd-vhosts.conf from apache folder in xampp instalation with something like that
<VirtualHost *:80>
ServerAdmin whatever#whatever.com
DocumentRoot "PATH TO YOUR FOLDER"
ServerName YOUR IP
ServerAlias YOUR IP
</VirtualHost>
After that you must restart apache in XAMPP control panel (MySQL not necessary)
THE SOLUTION ABOVE WILL LET YOU SEE YOUR CONTENT FROM ANYWHERE AS LONG AS YOUR LOCAL PC IS TURNED ON AND HAVE INTERNET CONNECTION. THE SOLUTION BELOW (I DIDN'T TEST IT, BUT I GUESS IT WILL WORK) WILL LET YOU ACCESS YOUR CONTENT FROM LOCAL NETWORK ONLY.
edit your httpd-xampp.conf file as following and after that you should probably need to perform a browser cache cleaning
# New XAMPP security concept
#
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
Order deny,allow
#Deny from all
#Allow from 127.0.0.0/8
Allow from all
ErrorDocument 403 /error/HTTP_XAMPP_FORBIDDEN.html.var
</LocationMatch>
When you add 192.168.1.105 localhost on the other PC (the one you want to use to view your website), it will look for a website on the same machine. Delete the entry from the hosts file and enter the IP address in your browser and it should work if the webserver is running.

Issue with Virtual Host on Zend Server CE and Mac OSX

I'm using Zend Server CE 5.6.0 on Mac OSX.
My httpd.conf has the following line, adding the virtual hosts file:
Include conf/extra/httpd-vhosts.conf
At that file, I have the following:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localtextil.drupal.lh
DocumentRoot /usr/local/zend/apache2/htdocs/Obiz/LocalTextil-Portal/drupal
</VirtualHost>
So, by definition, when I try to access localtextil.drupal.lh, it should redirect me to its document root.
The problem is, when I try to access that host, I got an error.
And when I simply access localhost, I go to the site located on /usr/local/zend/apache2/htdocs/Obiz/LocalTextil-Portal/drupal.
What am I doing wrong here?
Two things - first is that the virtualhost definitions (as I understand it) override apache's mappings between directories and servernames. The first defined virtualhost is what apache will use as a default when it can't find a map - so it should be a generic setup (reflecting your original domainname, in your case, localhost) first, then your specific setup following it.
Second is that if your folder is outside of where you have given apache permissions to read, then you may get an error. The directory permissions are set by a DocumentRoot directive - however:
Now when a request arrives, the server will first check if it is using an IP address that matches the NameVirtualHost. If it is, then
it will look at each section with a matching IP address
and try to find one where the ServerName or ServerAlias matches the
requested hostname. If it finds one, then it uses the configuration
for that server. If no matching virtual host is found, then the first
listed virtual host that matches the IP address will be used.
As a consequence, the first listed virtual host is the default virtual
host. The DocumentRoot from the main server will never be used when an
IP address matches the NameVirtualHost directive. If you would like to
have a special configuration for requests that do not match any
particular virtual host, simply put that configuration in a
container and list it first in the configuration file.
The Apache document page on name based virtual hosting is here, it should help give some ideas. Basically you need to look at the definitions you have for DocumentRoot and the servernames, and go through them making sure they are all "ok".

VirtualHosts does not work on Mac OS 10.7

I want to create VirtualHosts on Mac OS 10.7 and therefore I edited the /etc/apache2/httpd.conf. I uncommented the line "Include /private/etc/apache2/extra/httpd-vhosts.conf" to include the virtual hosts. In the file /private/etc/apache2/extra/httpd-vhosts.conf I wrote the following:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/var/www"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/someFolder"
ServerName myApplication.dev
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/someOhterFolder"
ServerName myApplication2.dev
</VirtualHost>
There were two example virtual hosts before which I deleted. In my /etc/hosts file I added the following:
127.0.0.1 myApplication.dev
127.0.0.1 myApplication2.dev
I restarted my Apache and typed myApplication.dev and myApplication2.dev in the browser but I get an error "server not found" and it makes www.myApplication.dev in the browser (the same for myApplication2.dev).
Did I forget something to configure? I activated PHP in httpd.conf, mysql is installed also, but that has nothing to do with virtual hosts, I think.
Thanks for your help!
apachectl has an option -S to check vhost.conf file syntax. You can find these lines in vhosts.conf file.
> # You may use the command line option '-S' to verify your virtual host
> # configuration.
So, when you run
sh-3.2# apachectl -S
if you get Syntax OK result it means that there is no problem in your vhosts.conf file.
httpd: VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server zz.xxxx.com (/private/etc/apache2/extra/httpd-vhosts.conf:27)
port 80 namevhost zz.xxxx.com (/private/etc/apache2/extra/httpd-vhosts.conf:27)
port 80 namevhost yy.xxxx.com (/private/etc/apache2/extra/httpd-vhosts.conf:35)
Syntax OK
If conf file has any problem it will tell you error line(s) like
sh-3.2# apachectl -S
Syntax error on line 33 of /private/etc/apache2/extra/httpd-vhosts.conf:
CustomLog takes two or three arguments, a file name, a custom log format string or format name, and an optional "env=" clause (see docs)
make sure that your vhosts.conf file has true configuration.
I had the exact same problem using OS X Lion. I fixed it by adding "::1 myhost.dev" to /etc/hosts:
127.0.0.1 myhost.dev
::1 myhost.dev
Incidentally, the ::1 also fixes a bug that makes page loading very slow on virtual hosts served from the Mac.
Are you using an HTTP proxy? If so, make an exception for myApplication.dev and myApplication2.dev.
What I meant was that the problem "server mot found" means that your browser cannot find the ip adresses of the hosts "myapplication.dev". This may be because you're using an http proxy, possibly one configured by your hosting company. In any case, you don't even reach the server, so you never get to try the virtual host configuration at all.
To just try the virtual host configuration, you can use telnet in a Terminal window and talk HTTP directly to the server, like this:
yourmacbox:~ yourname$ telnet 127.0.0.1 80
You should see the following text:
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Then you type
GET / HTTP/1.0
Host: myApplication.dev
Now, hopefully you should see some response from your web server. This shows that once you can connect to it, the virtual hosts things works.
I had the same problem, and noticed that the ServerRoot "/usr" was set as shown and incorrectly after the 10.7 upgrade. The httpd.conf file was still under /etc/apache2, but this setting in it was pointing to the wrong place. Once I had fixed that by changing to ServerRoot "/etc/apache2", all my previous virtual host configuration got picked up properly.
I also had to re-enable virtual hosts by uncommenting line 477 as mentioned here http://brettterpstra.com/fixing-virtual-hosts-and-web-sharing-in-mountain-lion/ That didn't quite kick in until I had fixed the path issue above.

Error: "VirtualHost *:80 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results"

I'm running WAMP v2.0 on WindowsXP and I've got a bunch of virtual hosts setup in the http-vhosts.conf file.
This was working, but in the last week whenever I try & start WAMP I get this error in the event logs:
VirtualHost *:80 -- mixing * ports and
non-* ports with a NameVirtualHost
address is not supported, proceeding
with undefined results.
and the server won't start. I can't think of what's changed.
I've copied the conf file below.
NameVirtualHost *
<VirtualHost *:80>
ServerName dev.blog.slaven.net.au
ServerAlias dev.blog.slaven.net.au
ServerAdmin user#host.com
DocumentRoot "c:/Project Data/OtherProjects/slaven.net.au/blog/"
ErrorLog "logs/blog.slaven.localhost-error.log"
CustomLog "logs/blog.slaven.localhost-access.log" common
<Directory "c:/Project Data/OtherProjects/slaven.net.au/blog/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
EDIT: I meant to add, if I change the NameVirtualHosts directive to specify a port, i.e
NameVirtualHost *:80
I get this error:
Only one usage of each socket address (protocol/network address/port) is normally permitted. : make_sock: could not bind to address 0.0.0.0:80
NameVirtualHost *:80
I get this error:
Only one usage of each socket address (protocol/network address/port) is normally >permitted. : make_sock: could not bind to address 0.0.0.0:80
I think this might be because you have somthing else listening to port 80. Do you have any other servers (or for example Skype) running?
(If it was Skype: untick "Tools > Options > Advanced > Connection > Use port 80 and 443 as alternatives for incoming connections")
Well, it seems the problem there is the way (and order) in which you assign the ports.
Basically, *:80 means "use port 80 for all hosts in this configuration". When you do this, Apache tries to bind that host to 0.0.0.0:80, which means that host will receive every single packet coming to the machine through port 80, regardless of what virtual host it was intended to go to. That's something you should use only once, and only if you have one host in that configuration.
Thus, if you have the same *:80 directive on two hosts in the configuration file, the server won't load because it will try to bind 0.0.0.0:80 twice, failing on the second try. (which explains the "Only one usage of each socket address (protocol/network address/port) is normally permitted. : make_sock: could not bind to address 0.0.0.0:80" message).

Resources