Change the "IP Address" portion of a local Apache2 server to some consistent string - apache

I have an Apache2 server running in Debian 9.
I am using it to host a custom MediaWiki Wiki.
To navigate to the Wiki I use something of this form "10.200.200.20/mediawiki" where the Apache2 server is running on 10.200.200.20.
This works fine however sometimes the IP Address (10.200.200.20) will change and then everyone on the local network navigating to the Wiki will have to be notified and use the new IP Address which is a hassle.
I wish to change it to something consistent, for example "OurWikiServer/mediawiki" it doesn't really matter that much as long as it can always be found at the same place.
I know this is possible as the MediaWiki installation was previously maintained by someone else who used XAMPP in Windows 7 and it was configured to be found at "stringHere/mediawiki" on the local network.
I have tried changing it in /etc/hosts and can get it changing on individual machines as expected, however have no idea how to get it working network wide.

The best way to do this is to define the IP of this station static. This can be done via reservation in DHCP server or assign IP outside of the DHCP IPs. Also consider adding small DNS server to provide hostname instead of IP

Related

Localhost works, but ip gives timout

I am trying to setup a LAMP environment on my laptop with Ubuntu 18.04.
I have no experience real previous experience with this and all tutorials i find are just a step for step guide on how to setup, but none explain what you are exactly doing.
So I don't know why I am having this problem.
After installing all parts of LAMP I can access localhost, and I see the apache default page.
But if I try to go to my IPaddress, (the ipaddress I found with curl -4 icanhazip.com) the page loads for a while and then tells me this:
Firefox can’t establish a connection to the server at 213.127.26.xxx
So my question is am I using the right IPaddress and how can I make apache work from my IPaddress? Because phpmyadmin will not work on localhost.
The issue is likely that your local ports (i imagine your web server is running on port 80 or 8080) are not being forwarded through your router. Your router likely uses something called “NAT (network address translation)” to expose all of the internal IP addresses on your network through a single “public” IP address, in your case 213.x.x.x (you should never post this here unless you’re 100% positive your network is secure!). Your router needs to be configured to forward port 80 on 213.x.x.x to your machine’s “internal” ip address, likely something like “192.168.x.x” or “10.0.x.x”. A search for “port forwarding ” should help you out
Alternatively, ngrok is a nice free tool which you can use to expose your port on a public address. By running nginx http 80, it will provide you with a temporary url where you can reach your site (on a free plan, it will only provide you that url for one day, so you will need to re-run it)
First, you have to find out on which ports your server is running.
After that, you have to go into your router's settings and add port forwarding entries for these ports, to make sure that your router forwards the requests to the right device.

Apache virtal hosts unreachable

I'm doing local php development with apache and virtual hosts. For some reason my virtual host sites have stopped responding.
Chrome error:
This web page is not available
ERR_ADDRESS_UNREACHABLE
Firefox error:
Server not found.
I haven't made any change to the server config or php ini files since I set them up, and the sites were working fine earlier today. This affects all the virtual host sites I created, but apache still seems to be running fine on localhost.
I've tried restarting my system (ubuntu) and checked the apache access and error logs. Attempts made to access virtual hosts are not logged at all (since the problem started).
I have no idea what's going on. Does anyone have any advice?
Thanks.
Ok, I've solved it, but I think it's handy for others' reference.
My router had re-assigned my IP Address (I have no idea why). Therefore the IP Address in /etc/hosts for those virtual hosts domain names did not match the address of my dev PC.
Solution: I just updated the IP address in virtual hosts.
Another strange thing is the router seems to have removed all the IP Addresses of devices not currently connected. In the past it has kept them around even though they are not connected, but that's another matter and I should look into it (Well I think I had assigned them a static IP, but it's been a while since I've touched the router settings).

ip addressed not responding : but 127.0.0.1 responding : Apache

I currently have Apache running as part of XAMPP and I am able to run the PHP scripts by accessing them at 127.0.0.1/<program_name>.php but when I try to access them as <my_ip>/<program_name>.php I get no response.
Am I doing something incorrectly or does my configuration need fixing?
assuming you are trying to access from an external ip address you need to setup your router (port forwarding) to send web traffic to the LAN ip of your machine.
you also may need to disable various firewalls at various points in your network.
In short there is not enough information given to provide you a definitive answer.

Does the hosts file affect to adhoc connected devices?

I've got a local Apache2 server on Ubuntu 12.04
with virtual hosts, so in the 'hosts' file I pointed
the virtualhost name to the local IP address -192.168.1.33-.
So 'http://mySite.local' points to '192.168.1.33', it works fine
in the browser.
Now I want to test the same in a cellphone connected to the machine
through a wlan-adhoc network created in my notebook with shared connection.
I can see the root folder if I access to '192.168.1.33' correctly,
but not if I access to 'http://mySite.local'
I assume the '/etc/hosts' file is not affecting the traffic through the adhoc network.
is this correct? Can I change this behaviour? is possible?
You are correct to assume that the hosts file only affects connections that originate from the machine to which the host file belongs. Other traffic already needs to know the IP address it will need to connect to before it reaches your machine. Depending on how much access you have to your phone, getting it to recognize your own domain name like this maybe more work than it's worth.
I say this because you would need to do one of the following:
Edit the equivalent of the hosts file on your phone (if such a file exists in an accessible way)
OR
Set up a local DNS server to serve this info to your phone AND get your phone to use it for DNS resolution.
Without knowing what phone you have, I can't say for sure how hard either of these will be. But I would guess neither one is going to be nearly as easy as typing in the IP and bookmarking it in your phones browser.
The hosts file only works for the machine it is local on. It is not passed on or used as a data source for any DNS service. You would have to have a hosts file local to your cellphone, and I'm not sure that this is possible.

Error with DOJO when using IP

Strange error with an Project using dojo:
if i call : http://localhost/project everything works like expected.
if i call : http://127.0.0.1/project everything works like expected.
if i call : http://192.168.2.1/project i get the following error (ONLY in IE6!):
"Bundle not found, locale.."
Any ideas?
Iam running Zend Server CE with PHP 5.2
if i add: 192.168.2.1 to "hosts" it works (windows)
Sounds like Zend server is performing some kind of virtual site support using the site name as a partial domain.
I can't say 100% if/how it is beacuse I don't use Zend, but I can explain the principle using Apache as an Example.
There are 3 ways in which a web site can be virtually hosted under a single web server application, this applies to most servers on the market today, Apache, IIS, nginx and many others.
It all boils down to one thing, giving one running server application instance the ability to host multiple individual websites.
The 3 methods of seperating sites are as follows:
By IP address : If you have multiple IP addresses (Usually -but not always beacuse you have multiple network interface cards) then you can tell your server application to listen to one IP for one site, another IP for another site and so on. If you browse to one IP you'll get one site, and likewise the other on the other IP.
By Port Number : If your using only one IP address, then you can bind to multiple port numbers, port 80 is generally the default for web servers, but by browsing to an address and pinning the port number on the end (http://mysite.com:99) you'll force the browser to use that port. You can then have multiple websites listening on different ports and select them manually at browse time as required.
By Host Name Header: This is by far the most common way of supporting multiple sites, all web servers that understand the HTTP/1.1 protocol have to obey a header field in the request that contains the host name, when a request comes in for EG: http://mysite,com/ then there will be an entry in the request header that looks like 'Host: mysite.com' the webserver can then use that to say, oh yes.. I know which one that is.. and it then selects and serves the correct website.
The problems start to arise however when you start to use IP addresses that generally cannot be resolved or have no DNS name, because the web server then doesn't know which hostname to tag it to.
As an example in Apache, if you set up a virtual host, then try to browse that server using just the IP address, you'll get the default server, which in many cases won't even be configured to respond correctly or display anything.
To compound this, going up to web application layer, many frameworks also do their own checks on hostnames and other variables passed to them by the web server, and many make decisions on how to operate based on this information.
If you've gotten to the default web application by IP address, then there's a high chance that the framework may get confused at being presented with an IP address as a host name.
As the OP noted, in many cases, you can add a name to your hosts file and use this as a poor man's DNS substitute, the file to modify can be found in the following locations:
c:\windows\system32\drivers\etc\ - on windows
and
/etc/
on Linux/Unix
The file is generally just called 'hosts' and is a plain text file. Adding a line like:
123.456.789.123 myserver
Will tie http://myserver/ to http://123.456.789.123/
If you can, and your doing a lot of web applications it may be worth setting up your own DNS server, most Linux distros will allow you to install 'Bind' and I do also believe there is a version available for windows too.
I'm not going to go into the pro's and cons of private DNS servers here, it's a whole other subject in itself, but if your likely to be doing a lot of additions to your hosts, then in the long run you'll find it a better option.