mmonit not using remote server IP, using localhost instead - monit

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.

Related

Can not access web app hosted on apache from local network

As a newbie set up mediawiki in apache httpd on my linux pc. In the corresponding .conf file "require all granted'" is set. The pc was assigned static IP 192.168.0.2 by the router. The port 80 of the pc is opened for any device. I visited http://192.168.0.2/mediawiki/index.php from the host. It worked as expected. Now I tried to visit the same address from my android phone connected to the same network and I was presented with the message "127.0.0.1 refused to connect" by chrome. I noticed that the part http://192.168.0.2 had been replaced by https://127.0.0.1 in the address bar. The same thing also occurred on Firefox on my phone. I can still visit http://192.168.0.2 from my phone and it works just fine. So what is happening here and how to solve this problem?
EDIT: The problem is solved. Mediawiki has this LocalSettings.php file which gets automatically created during installation. It contains a field "$wgServer" which is the "The protocol and server name to use in fully-qualified URLs" as shown in the documentation. This value was automatically set to "http://127.0.0.1" during the installation. Thereby whenever I was trying to connect to mediawiki from my phone I was actually getting redirected to that same phone. I changed the value to "http://192.168.0.2" and now everything is working fine!
Looks like something happened at the connection from your mobile phone to the pc hosting the web server.
Your configuration looks fine even tho you provided almost no details at all: according to your description, I suspect the problem is on your phone or on your router because the domain and url switched from 192.168.0.2 to 127.0.0.1 and the protocol switched from http to https.
You should try the same test from another pc connected to the same network.
You can have a better understanding of what's happening, testing the connection from command line using curl:
$ curl -v http://192.168.0.2/mediawiki/index.php
The output will give you some details of what's going on if the redirect was requested by the webserver or not.
My guess is that your apache is configured to listen to 127.0.0.1 or localhost (it's the default). Open httpd.conf or your virtual host configuration file and look for Listen. Here's some snippets from the official documentation:
The Listen directive tells the server to accept incoming requests only on the specified port(s) or address-and-port combinations. If only a port number is specified in the Listen directive, the server listens to the given port on all interfaces. If an IP address is given as well as a port, the server will listen on the given port and interface. Multiple Listen directives may be used to specify a number of addresses and ports to listen on. The server will respond to requests from any of the listed addresses and ports.
For example, to make the server accept connections on both port 80 and port 8000, on all interfaces, use:
Listen 80
Listen 8000
To make the server accept connections on port 80 for one interface, and port 8000 on another, use
Listen 192.0.2.1:80
Listen 192.0.2.5:8000
More information at
https://httpd.apache.org/docs/2.4/bind.html

Remote access of network computer

I am not sure how or if this can be done. I have a home network and would like to see a computer,not the server, via a remote location. I have Apache on my server. Example: the network computers I would like to see ip 152.254.1.33. Is there a way to add this ip to Apache root directory? I have tried to add a shortcut with in the root directory and it only works on the home network, will not via remote connection.
I need some clarification here on what you are trying to acomplish, are you trying to access the Apache website outside of the local network?
If that is the case, Apache is automatically set to listen on all network interfaces, you can check this in your virtual host configuration in the sites-enabled directory of your apache installation.
You should see something like in the 000-default.conf
You can test if apache is serving pages up correctly using the command
curl 127.0.0.1
You should see the HTML of the page being served.
If this is the case, then it's likely the firewall on your machine/router or your ISP is blocking the required ports. You can allow Apache through the firewall on Ubuntu using sudo ufw allow Apache Full
If you give me some more info in comments we can probably work this out.

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

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.

How can I access monit http remotely

I have been trying for hours to configure monit so I can access it remotely from a web browser from http://:2812 but it always times out. I have Nexus running on the same instance at http::8081 so I know basic connectivity works: My monitrc contains
set httpd port 2812
# use address localhost # only accept connection from localhost
allow localhost # allow localhost to connect to the server and
allow admin:monit # require user 'admin' with password 'monit'
allow 50.67.165.130 # remote host
Where remote host is where I am trying to connect from. Is there some other special magic to be able to access the monit httpd remotely?
Strange that this has to be so hard.
I have been through the same problem, I dont think the configuration likes comments right below the "set", try to put the lines without comments right below the "set". For example:
set httpd port 2812
allow admin:monit
Do also watch the log for errors:
tail -f /var/log/monit.log
I had the same issue for hours but finally solved.
In case you're using a firewell (ufw in my case), just add a rule to allow the trafic for the port:
sudo ufw allow 2812/tcp
2812 being the port you're trying to connect from, then http://your-ip-adress:2812
You have to configure Monit to allow remote access by adding your remote system IP address. We can add multiple IP addresses to access the HTTP interface from multiple systems as shown below.
set httpd port 2812 and
# use address localhost # only accept connection from localhost
allow localhost # allow localhost to connect to the server and
allow 50.67.165.130 # remote host
allow 50.67.165.135 # remote host
allow admin:monit # require user 'admin' with password 'monit'
Also, open the port 2812 by updating your firewall.
You have misses the and after the port number which is causing issues with your installation.
Also refer Install Monit On Ubuntu for complete details.
What you can also setup is
allow 0.0.0.0/0.0.0.0
but before you do, check also if you restricted connections to an address like localhost