Configurating apache vhosts to access domain from outside of local network - apache

Configuration
I am running Windows Server 2012 with XAMPP installed in C:\xampp
Apache running as a Service
I have edited host file in C:\Windows\System32\Drivers\etc, added following
127.0.0.1 landing.local
I added vhost in C:\xampp\apache\conf\extra\httpd-vhosts.conf
NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
DocumentRoot C:/xampp/htdocs/
ServerName localhost
ServerAlias localhost
</VirtualHost>
<VirtualHost landing.local:80>
DocumentRoot "C:/xampp/htdocs/landing"
ServerName landing.mydomain.com
ServerAlias landing.mydomain.com
</VirtualHost>
I also uncommented following line in httpd-vhosts.conf
NameVirtualHost *:80
and in httpd.conf
LoadModule vhost_alias_module modules/mod_vhost_alias.so
Include "conf/extra/httpd-vhosts.conf"
and Apache is configured to Listen on port 80.
Listen 80
Where landing.mydomain.com is redirected to Public Virtual IP from Windows Azure.
Problem
When I access locally http://landing.local/ site works
But when I try to access landing.mydomain.com from inside network it doesn't work, instead it redirects to main localhost site.
So I tried using landing.mydomain.com in hosts and landing.mydomain.com in vHost.
<VirtualHost landing.mydomain.com:80>
DocumentRoot "C:/xampp/htdocs/landing"
ServerName landing.mydomain.com
ServerAlias landing.mydomain.com
</VirtualHost>
This time I am able to access landing.mydomain.com from inside network, on server but when I try to access it from outside local network it doesn't work.
I also tried editing host file and pointing landing.mydomain.com to my Public Virtual IP or Internal IP address. Didn't help...
<VirtualHost landing.mydomain.com:80>
DocumentRoot "C:/xampp/htdocs/landing"
ServerName landing.mydomain.com
ServerAlias landing.mydomain.com
</VirtualHost>
Host file
255.255.255.255 landing.mydomain.com
Where 255.255.255.255 is my Public Virtual IP and 255.255.255.254 Internal IP but it didn't work. It would just open my localhost (homepage of mydomain.com)
255.255.255.254 landing.mydomain.com
Also I tried to
Bind Apache to Public Virtual IP 255.255.255.255 by editing httpd.conf
Listen 255.255.255.255:80
(OS 10049)The requested address is not valid in its context. : AH00072: make_sock: could not bind to address 255.255.255.255:80
AH00451: no listening sockets available, shutting down
Apache did work when I binded to Internal IP Address, but still I was unable to access landing.mydomain.com from outside the network, it again redirected to my homepage (server localhost)
Listen 255.255.255.254:80
I also received this warning when starting from dos, but it's not the cause of my problems, that's the line I uncommented from httpd.conf cause I read somewhere on boards it helped to some to solve their problems, didn't help me at all, same with commented and uncommented.
Host >>
127.0.0.1 landing.mydomain.com
With this configuration I was unable to access subdomain from localhost. I was still able from outside the network since it was redirect using A record to my server Public Virtual IP.
AH00548: NameVirtualHost has no effect and will be removed in the next
release C:/xampp/apache/conf/extra/httpd-vhosts.conf:19
Solution
So I changed the IP address in host file also to Internal IP Address, 255.255.255.254
255.255.255.254 landing.mydomain.com
And left the vhost as.
NameVirtualHost localhost:80
<VirtualHost localhost:80>
DocumentRoot C:/xampp/htdocs/
ServerName localhost
ServerAlias localhost
</VirtualHost>
<VirtualHost landing.mydomain.com:80>
DocumentRoot "C:/xampp/htdocs/landing"
ServerName landing.mydomain.com
ServerAlias landing.mydomain.com
</VirtualHost>
If someone is familiar with configuration of Apache on Windows Server 2012 please any help is appreciated :)
Update
I forgot to mention you should not forget to configure Windows Server Firewall (allow on ports 80 and 443, tcp incoming traffic) as well as endpoints (tcp 80 and 443) on Azure platform.

Related

apache port disabled yet still working

So I have inherited a linux server and am unclear about its apache configuration.
In the httpd.conf file it has this..
Listen 80
#Listen 443
Based on http://httpd.apache.org/docs/2.2/bind.html
"Note that if the <VirtualHost> is set for an address and port that
the server is not listening to, it cannot be accessed"
Yet this server uses SSL and is receiving requests successfully.
Here is one of the vhost directives..
<VirtualHost *:80>
ServerName www.somesite.com
DocumentRoot /var/www/html/somesite
</VirtualHost>
<VirtualHost 10.0.0.5:443>
DocumentRoot /var/www/html/somesite
ServerName www.somesite.com
SSLEngine on
SSLCertificateFile /sslcerts/mycert.crt
SSLCertificateKeyFile /sslcerts/mycert.key
SSLCertificateChainFile /sslcerts/mycert.gd_bundle.crt
</VirtualHost>
The server is successfully receiving https requests to www.somesite.com
Is there some other configuration I am not seeing?
(also I'm not quite sure if using the internal IP 10.0.0.5 is correct)
thanks to #arkascha a simple grep showed that there was an additional config file where port 443 was enabled

How to customise my URL which is having IP Address

Is it possible to configure my URL which has my IP address on it- like: "http://192.168.xx.yy/index.php". The situation is when I run Apache server in my PC, and load localhost in it. I know it is possible after hosting with external server, but is there any way we can configure within our localhost?
How to configure the Apache files to make this happen? I tried in my localhost, editing the "httpd.conf" by adding this inside like this - please tell me where I am getting the issue!
ServerName localhost:80
HostnameLookups Off
<VirtualHost *:80>
# This first-listed virtual host is also the default for *:80
ServerName www.example.com
ServerAlias example.com
DocumentRoot /www/domain
</VirtualHost>
<VirtualHost *:80>
ServerName other.example.com
DocumentRoot /www/otherdomain
</VirtualHost>
DocumentRoot "c:/wamp/www/"
Yes, you can play with multiple IP addresses on your machine. Configuration depends on your OS. Article Create Multiple IP Addresses to One Single Network Interface is for linux.
But, better way is to use VirtualHosts based on host names or (simplest) on ports. So you can get http://siteA.mycoputer.localhost, http://siteB.mycomputer.localhost in the first case and http://192.168.x.y:8000, http://192.168.x.y:9000 in the second case
Here is Apache Server config example from Apache Server 2.2 documentation
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example.org
# Other directives here
</VirtualHost>

Multiple Virtual Hosts on Different Ports in WAMP

So I have this problem...
I use WAMP and have set up perfectly working Virtual Hosts in the past, but now I have come to something I never foresaw.
I am trying to do this:
Access C:\wamp\www through http://localhost
Access D:\somethingelse through http://localhost:8080 OR http://something.dev
I much prefer using the proper http://something.dev, as the working site is http://something.co, and so I can keep them separate.
I have followed guides and read forum posts, but all I have manages to do so far is this:
Access C:\wamp\www through http://localhost OR http://something.dev
Access D:\somethingelse through http://localhost:8080 OR http://something.dev:8080
Anybody got any idea how you would do this? Here's my VirtualHost Code:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "C:\wamp\www"
ServerName localhost
ServerAlias www.localhost.com
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
<VirtualHost *:8080>
ServerAdmin webmaster#something
DocumentRoot "D:/something/www"
ServerName something.dev
ServerAlias www.something.dev
ErrorLog "logs/something-error.log"
CustomLog "logs/something-access.log" common
<directory "D:/something/www">
Options Indexes FollowSymLinks
AllowOverride all
Order Allow,Deny
Allow from all
</directory>
</VirtualHost>
And in httpd.conf I have this
Listen *:80
Listen *:8080
And my hosts file is working and points both of these to 127.0.0.1
(The reason I want to do this is that when I code on my machine I use the http://something.dev, but I run Livereload Windows, and test my website simultaneously on an iPhone and iPad on the same local network, but without any access to iOS's equivalent of the hosts file. It also allows me to open up only a specific part of my server to the internet, through port forwarding on my router.)
I suppose you have solved the issue. Anyway is good to share some nice information on how to set up multiple Virtual Hosts in Wamp. This is working for me:
http://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp
In my case I am working with ports 8080 and 8181. 8080 is redirecting to a subfolder under c:\wamp\www\myfolder, while 8181 is redirecting to root c:\wamp\www.
To make 8181 work I had to edit httpd-vhosts.conf, hosts (in \drivers\etc folder) and httpd.conf.
In httpd.conf my Apache is listening:
Listen 8080
Listen 8181
also I uncommented:
Include conf/extra/httpd-vhosts.conf
my root is pointing to
DocumentRoot "c:/wamp/www/myfolder"
root directory is configured as:
<Directory "c:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from ::1
Allow from localhost
</Directory>
and added:
<VirtualHost *:8181>
DocumentRoot "C:\wamp\www"
ServerName name-of-my-fake-server
</VirtualHost>
in httpd-vhosts.conf I have set:
NameVirtualHost *:8181
in hosts (c:\windows\system32\drivers\etc) I have added:
127.0.0.1 localhost
127.0.0.1 name-of-my-fake-server #My Test Site
Doing that I have now two ports working 8080 and 8181: so 8080 points to directory "c:\wamp\www\myfolder" and the other port 8181 points to my root folder "c:\wamp\www\"
Using * as the hostname requires the use of NameVirtualHost:
NameVirtualHost *:80
NameVirtualHost *:8080
For those with MAMP, edit the httpd.conf
nano /Applications/MAMP/conf/apache/httpd.conf
Add Listen for each port
Listen 80
Listen 8080
And the ServerName too
ServerName localhost:80
ServerName localhost:8080
Once done that, edit httpd-vhosts.conf
nano /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Define NameVirtualHost
NameVirtualHost *:80
NameVirtualHost *:8080
And the VirtualHost's
<VirtualHost *:80>
DocumentRoot "/Users/yourUser/path/project1"
ServerName project1.local
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot "/Users/yourUser/path/project2"
ServerName project2.local
</VirtualHost>
Of course you need to have project1.local and project2.local in your hosts file
sudo nano /etc/hosts
And add
127.0.0.1 project1.local project2.local
Restart MAMP and you could access your vhost by
project1.local
project2.local:8080
project2 could be access also in your network or with a external IP (e.g to test from a different device like a mobile phone). Assuming your IP is 192.168.1.10
192.168.1.10:8080
The question is a little about it. But I assumed that it's near there and may be helpful for somebody.
Recently I met the problem when I need to get access to a few resources (debian repository, my website and phpmyadmin) by one external IP address and port.
After learning the problem I found technology named as reverse proxy. It like proxy but server is accepting all connection from many users and redirect to one target (your server).
I made simple Docker image and docker-compose file and push that to github.com/urpylka/docker-nginx-reverse-proxy and hub.docker.com.
Config file is very simple:
server {
listen 80;
server_name smirart.ru robotic.lol;
location / {
proxy_pass http://robotic.lol:1080/;
}
}
server {
listen 80;
server_name repo.smirart.ru;
location / {
proxy_pass http://8.8.8.8:2080/;
}
}
You can use that for few web-servers running by different IP.

Accessing localhost Webserver Over Network

I am using my local machine as a development server. I have my hosts file set up as such:
127.0.0.1 localhost
127.0.0.1 cdog24
127.0.0.1 xxxxxorg
127.0.0.1 newintranet
My httpd-vhosts.conf file is set up as follows:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "D:\Webserver\htdocs"
ServerName localhost
ServerAlias localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:\Webserver\htdocs\cdog24"
ServerName cdog24
ServerAlias cdog24
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:\Webserver\htdocs\xxxxxorg"
ServerName xxxxxorg
ServerAlias xxxxxorg
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:\Webserver\htdocs\newintranet"
ServerName newintranet
ServerAlias newintranet
</VirtualHost>
I am running xampp and can access each site on my local machine respectively by typing in:
http://localhost
http://cdog24
http://xxxxxorg
http://newintranet
When i go to a different computer on my network, I assume I have to type int he name of my machine or use the IP address. So, when I type in the following:
http://machinename/cdog24 or http://10.1.0.24/newintranet
I am taken to a 404 page.
What am I missing? Firewall on local machine or network do not factor as they are both off. I am on a Windows 7 local machine, the remote machine is also Windows 7.
Thanks for any help.
You will need to edit the hosts file on the remote machine (where the browser is running, not the server):
x.x.x.x cdog24
x.x.x.x xxxxxorg
x.x.x.x newintranet
Change x.x.x.x to the IP address of the Windows box that is running the server.
Now you should be able to browse to, say http://cdog24/ in your browser.
However, do NOT add a localhost entry that points to the other machine. localhost should always point to 127.0.0.1!
Have you tried with just http://machinename/ ?
http://machinename/directory would require that the document root be pointing to htdocs itself.
You need to work out what the IP address of your machine is on your network, and then edit teh hosts files on the other machines to point to yours
<your local IP> cdog24
<your local IP> xxxxxorg
<your local IP> newintranet
You maybe also have to update the apache conf file to work from your network address rather than 127.0.0.1.

Access Apache VirtualHost from any computer on LAN?

I have wamp setup with quite a few websites setup as virtual hosts like this in httpd.conf
<VirtualHost 127.0.0.1>
ServerName project1.local
DocumentRoot "c:/wamp/project1/"
</VirtualHost>
I have these input in the wamp machine's host file and I can access them just fine on that machine.
127.0.0.1 project1.local
However, when I try to put an entry on my OSX machine as (192.168.1.101 being the internal ip of the wamp machine) it won't pull the page up.
192.168.1.101 project1.local
Is there something else I need to do to make this work from other machines? Thanks!
You either need <VirtualHost 192.168.1.101> (in addition to 127.0.0.1), or simply use <VirtualHost *> to put the VH on all addresses.
Just add below code in your virtual host config file
In the below code,
'Client_IP' is the IP of the machine from where you want to access the directory without using any ip on the address bar, just put severname in the address bar like 'servername/'.
<VirtualHost *:80>
ServerName servername
DocumentRoot d:\wamp\www\dir_name
<Directory "d:\wamp\www\dir_name">
Order Allow,Deny
Allow from 127.0.0.1 Client_IP
</Directory>
</VirtualHost>
Then, set same servername that you have used for the virtual host on apache server like,
server_ip servername
in the client machine c:/windows/system32/drivers/etc/hosts file.