Ubuntu Server with Apache domain management - apache

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

Related

mmonit not using remote server IP, using localhost instead

I've got an install of mmonit with various servers reporting into it. The monitoring is working, but trying to restart any servers results in it trying to contact itself (on localhost) and not the origin server IP.
I face a similar issue on ec2 via autoscaling, where the internal IP is assigned, not the public IP. Thus we get the same error, but it shows the AWS internal ec2 IP.
Our mmonit file is super simple, and doesn't mention localhost:
set httpd port 2812
allow xxx.xxx.xxx.xxx
allow monitcli:xxxxxxxxxxxxxxxx
In the monit host settings, it shows localhost, or the ec2 internal IP, and sure, I can manually override this, but that's a PITA.
Is there a way to push the correct external IP address from monit > mmonit in the config file?
Anyone have any insights here?
Use a proper hostname or ipaddress in the Monit monitrc files.
set httpd port 2812 and
use address 1.2.3.4
allow localhost
allow 1.2.3.0/24
The "use address" address used by Monit should be reachable by your M/Monit system. And the "allow" address mask should include the M/Monit system and the Monit system, you can add multiple address masks.

Host the site on my computer and make is available on internet

I have the following config on my computer:
OS: Ubuntu 18.04
Server installed: Apache2 (XAMPP)
I have static IP bound on my computer (Let's say 100.100.100.100)
I have developed my website on the localhost and now I want to point my IP address on my localhost so that my website should be accessible on internet
How can I do that?
P.S.: I obviously can use the shared/dedicated hosting but I don't want to go for that and my computer has 24*7 internet + power.
I think you can adding NAT rules to you router, if your Apache server use port 80 and 443 you could try NAT these ports from 100.100.100.100 to your external IP address or dynamic dns name (if you have one).
I think is better if you register a dyndns name, if you don't have a static external ip address.

Direct incoming port 80 traffic to local virtual host

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.

How to configure custom hostname to IP resolutions in my system for web development

Preface
A web app can potentially
serve different pages,
depending on the
hostname
that is requested by the browser,
even if all hostnames are resolved
to the same
IP address.
Example
For example, at
https://app.example.com,
which resolves to
1.2.3.4,
users will find the user interface
and at
https://admin.example.com,
which also resolves to
1.2.3.4,
awaits a dashboard
through which
only the app's owner can
administrate users and data
in the app.
What We Need
In short,
we need to enter,
for example,
http://admin.app:8000/
in our browsers
and have that admin.app resolve to 127.0.0.1.
The Question
How can I configure
custom hostname to IP address resolutions
in my development environment?
(Ubuntu and Derivatives) Configure NetworkManager's dnsmasq
Ubuntu Desktop's default networking configuration is
composed of NetworkManager and its slave dnsmasq.
The slave dnsmasq listens at 127.0.1.1 and /etc/resolv.conf lists it as the only nameserver.
This has
some benefits.
What it means for this purpose is that we have a fully configurable DNS server, comfortably configured by default.
We can create
/etc/NetworkManager/dnsmasq.d/hosts.conf
and put in it whatever address statements we'd like:
address=/admin.app/127.0.0.1
We can even use wildcards!
address=/.app/127.0.0.1
See the
dnsmasq documentation
for details
(look for --address).
Since dnsmasq is started by the network-manager service,
then I would assume that the following would restart it
so that new configuration would take effect:
$ service network-manager restart
But its init-script does not control slave dnsmasq.
Therefore the dnsmasq process must be killed and then
the above command would have it start again.
And that is it!
(Linux) User Specific HOSTALIASES File
Very limited
This would have been my preferred answer
because
it refrains from
altering system configuration.
But:
It does not support wildcards
It does not support hostname to IP address resolution
It does not support freely configurable subdomains
It will not work if you have a local DNS server,
which is the case in modern Ubuntu.
What is It
It is a user specific host aliases file.
Notice that the format is not the same as the hosts file.
In short, you create a file
which contains host aliases.
For example
foo localhost
bar localhost
and place it at ~/.hosts.
Then you set an environment variable
HOSTALIASES
with the path to the aliases file.
So, for this example
$ export HOSTALIASES=~/.hosts
If Testing In a Virtual Machine
In a virtual machine
127.0.0.1 and localhost
will not reach the host,
but the guest.
In VirtualBox, for example,
by default, the host can be reached
at 10.0.2.2.
So, the guest VM's hosts file can look like
10.0.2.2 host
10.0.2.2 app.host
10.0.2.2 admin.host
Proxy DNS Nameserver Inside a Virtual Machine
If you're setting up
a proxy DNS nameserver
inside a virtual machine
(perhaps for wildcard support in Windows)
the upstream nameserver
is usually provided by the host.
In VirtualBox, it is 10.0.2.3.
(Windows) Configuring Acrylic DNS Server
Acrylic DNS Proxy is easy to install and configure.
It can help us get hostnames with aliases quickly in Windows.
And it is open source.
Install it.
Open the hosts file (via the start menu entry).
Put in some entries, like 1.2.3.4 >app.
Clear its cache and restart it (via the start menu entry).
Set your DNS server to 127.0.0.1.
(Windows, Linux, OSX) System Wide Hosts File
Simply edit the
hosts file.
Its location
depends on the OS.
For example:
127.0.0.1 app.localhost
127.0.0.1 admin.localhost
On Windows you can use
this nifty open source GUI
for editing the hosts file:
Hosts File Editor.
Wildcards
The hosts file does not support wildcards!
Ubuntu Desktop
Since Ubuntu 12.04,
Ubuntu desktop comes with
a local DNS server,
which might not respect
the hosts file (/etc/hosts).
So, for Ubuntu desktop, this answer
is best.
(GNU/Linux)
Since all the major distributions are migrating (or already did) to systemd stack the proper place to implement wildcard support would be systemd-resolved: see https://github.com/systemd/systemd/issues/766 for details.
That would be the place to set custom overrides for DNS as well.
As for windows - its VM should just get DNS from host machine: it's to risky to run it on bare metal anyway.

Apache Tomcat IP mapping to domain name

I am having apache tomcat server on my windows machine. Also I can access this server from other machines on the network.
Now I want to map the IP+Port combination to a name ie currently I have to write http://10.xxx.xx.xx:8080/app_name but I want to access it as http://app_name
How can I go about it? Is there any solution which I can achieve by adding some mapping in apache server file? Also DNS server is not in my control, any way to get around this problem?
Thanks
Rohit
By not specifying a port number, you are defaulting to port 80. Your options are to either modify your server to listen on port 80 or define an external load balancer VIP that does a PAT from port 80 to 8080.
If you take the VIP route, the hostname is defined on the load balancer. If you don't have that option and DNS isn't an option either, you could manually modify your hosts file with an alias. However, this would require all remote users to have your hostname - IP mapping in their local hosts files (making DNS the more manageable solution).
When user types the URL in browser, browser will establish TCP connection with web server in the port 80 by default in case of HTTP, 443 by default in case of HTTPS.
Yes. If Web server exposes any port other than default port, port has to be mentioned in the browser URL to connect and get the data.