Direct incoming port 80 traffic to local virtual host - apache

I am running MAMP Pro on a Mac and I have port forwarding set up on my router to forward traffic to my server. For now I just have an IP for my computer, no domain name or DNS setup, although I could do that. What I want to do is forward incoming traffic to a particular virtual host on my server. e.g. MAMP has a localhost by default. I have a number of other virtual hosts, xxxx.local, and I would like to forward to a particular one. Can I do that by editing httpd.config or the hosts file.

Apache "sees" the "host name" of the incoming request and forwards it to the virtual host with the same same. All other requests are captured from "localhost".
It's called "single link multihoming",means one IP address for a lot of virtual hosts.
Greetings,
Peter

I actually just pointed one of my domains to my home server IP and that works since it has a domain name and I have a local virtual host setup. My original question was whether it is possible to do something like that if you just have an IP (i.e. can you send all requests to an IP to a particular single local virtual host rather than to the default localhost), and I guess the simple answer is no. It forwards those to the localhost.

Related

HTTPS setup problem with Virtual IP address

We are setting up for the HTTP configuration for our project with the httpd
But our physical IP address and the virtual IP address is not the same
Where the physical IP address is system IP address and virtual IP address is added in DNS configuration.
We need to setup httpd with the virtual IP address. not with the system IP address.
How can I do this without changing the DNS entry?
Please let me know the configurations for the httpd.
thank you.
You only need to bind http on port 80 (and 443 if you are not off-loading the secure layer).
Every request reaching your apache will be served according to the configuration (plain, virtualhost, etc).

Ubuntu Server with Apache domain management

I'm currently trying to set my Apache configuration on ubuntu server. I have one IP(ex: 34.228.1xx.xx) and one domain(ex: mydomain.com).
I succeed to connect "Apache2 Ubuntu Default page" using IP 34.228.1xx.xx
Then I added 34.228.1xx.xx mydomain.com in hosts file(/etc/hosts) and restarted apache using this command sudo service apache2 restart
But I can't see "Apache2 Ubuntu Default page" using domain mydomain.com, but I still can connect it using IP 34.228.1xx.xx
This is my first web hosting I know my question is messed.
Thanks you in advance.
0.0.0.0 is not a port, it's an IP. And it is a special one which shouldn't go to /etc/hosts. Remove it.
To access Apache on the local machine (on the same on which Apache is running), use "127.0.0.1" or "localhost" as host name in your browser.
On all other machines, use either the machine's IP or its DNS name.
Of course, you have to ensure that the DNS name is pointing to the right IP. This should be a public IP (not something like 192.168.x.x or 10.x.x.x etc.) If you haven't done so already, you must register this name with your DNS hosting provider as a DNS "A" record.
Additional points to consider:
Firewall on Apache machine must be open for incoming traffic on ports tcp/80 and/or tcp/443
If your server is behind NAT, there must be a "forwarding" rule on the NAT machine

Port forward port 80 to diff websites depending on sub-domain wherein contents reside in diff machines

In the coming months I'll be creating different websites. Actually, one has been up already for awhile but I shut it down because of internet issues.
My issue now is I want to create another website but just under a certain sub-domain. I want to do this so that I can maximize my domain. So I'll be creating say:
1. www.example.com
2. api.example.com
3. xyz.example.com
My home router forwards port 80 to a certain local IP 192.168.0.3 which is a virtual machine. I want to make contents of different websites to reside in different VMs to avoid conflicts. So those 3 websites, are in different VMs.
Now, how can I set my router to target a VM depending on the website being requested provided that my router only targets one IP to port forward port 80?
Am I correct that I'll be using reverse proxy of Apache2?
Update: Is this an ideal solution on websites with this setup? If not how is large corporations set it up?
first you have to configure the dns server of your domain to forward all domains to the same ip address (use some a A-Records)
a-record
and then configure Name-based virtual hosts in the configuration of your apache webserver.
Name-based virtual hosts
in this Virtual hosts you can forward to the VMs

Allow only specific domains

I have an apache 2.4 server with some virtual hosts, let's say I have aaa.com domain and a few subdomains, bb.aaa.com and cc.aaa.com, currently I want apache server to listen only aaa.com and bb.aaa.com and ignore cc.aaa.com or just redirect cc.aaa.com to aaa.com (btw I have no virtual host for cc.aaa.com).
So my objective would be to allow connections only from aaa.com and bb.aaa.com, any other connection (from direct IP or any other subdomain not handled by virtual hosts) should be redirected to aaa.com or just refused.
I did not found any solution for this, actually I am not even sure if it's possible.
If you don't have a virtual host for cc.aaa.com and if this domain is pointing to your server then by default apache will enter into the first virtual host. So you might want to set the redirect here.

website can be accessed using ip but not with the url(domain name) in wamp

from default httpd.conf to updating the host file and httpd.conf i tried but the website fails to open with domain name give
in host file
<my current public ip address> <domain name>
in httpd.conf
Listen [my public ip]:port
then restart of wamp server and finally restart of PC and of-course change of ip is done in above all.
But of no use
Please help
Thanks for time and response
Aaron,
I think you are misunderstanding the function of the HOSTS file.
The hosts file acts a little like a local DNS Server. Any changes you make to it will only effect the single PC that you made the change on.
What the HOST file actually does
When windows starts it starts a service called DNS Client also known as dnscache. That service reads the HOSTS file and seeds the dnscache with any domain names you put in it and the ip that should be connected to for each domain name.
Any program (the browser in this case) that wants to connect to a domain, checks this cache first, to reduce accesses to an actual DNS Server out on the web and therefore speed up the conversion of domain name to Ip Address.
So if you want external users, i.e. anybody on the internet to be able to access your site you have to either purchase a real domain name and get it pointed to your WAN ip address, or use a Dynamic DNS service like DYNDNS or NO-IP, to mention only a few, and get that dynamic dns service to point to your WAN IP.
You will also have to change your Apache config so it will serve that domain name, my suggestion would be to create a Virtual Host to do this.
This post may help with the process of creating a Virtual Host