how to create SubDomains on localhost - apache

i have changed this in my httpd.conf file
#Listen 1234
and made 2 virtualhost in my http.vhosts.conf
<VirtualHost 127.0.0.5:1234>
DocumentRoot "D:/SVN data/WebClient_PHP/trunk/current_project_re/public"
ServerName prod
</VirtualHost>
<VirtualHost 127.0.0.6:1234>
DocumentRoot "D:/SVN data/WebClient_PHP/trunk/current_project_dec/public"
ServerName dev
</VirtualHost>
also changed this in my host file in windows/system32/drivers/etc/host
127.0.0.5:1234 prod
127.0.0.6:1234 dev
after restarting my apache when i point to "dev" or "prod" both are not working

You are sure, both addresses point to your local machine?
If not, you just may use 127.0.0.1 in both files and let apache handle the document root, specified by your ServerName.
Oh, and remove the port declaration in the hosts file

Related

Xampp unable to load multiple sites

I am working on a project using xampp server. I have more than one project. So for this I have set my httpd-vhosts like below
<VirtualHost *:8080>
ServerName khpos.com
ServerAlias www.khpos.com
DocumentRoot "D:/xampp/htdocs/pos"
<Directory "D:/xampp/htdocs/pos">
Require all granted
</Directory>
</VirtualHost>
#my second site
<VirtualHost *:8080>
ServerName demopos.com
ServerAlias www.demopos.com
DocumentRoot "D:/xampp/htdocs/demopos"
<Directory "D:/xampp/htdocs/demopos">
Require all granted
</Directory>
</VirtualHost>
Whenever I try to hit localhost:8080/demopos it's redirecting towards .../pos
hosts file
127.0.0.1:8080 khpos.com
127.0.0.1:8080 demopos.com
How to set it
Any help would be highly appreciated
You should change the portnumbers of the second etc. sites. Now all port addresses are on port 8080, if you change those to an other port number you should be fine.
<VirtualHost *:8080> to <VirtualHost *:{port-number}>
Where port-number is an other port-number
127.0.0.1:8080 khpos.com
127.0.0.1:{port-number} demopos.com
you have 2 virtual hosts defined and also the names in hosts file. Please first remove the port numbers in the hosts file:
ServerName khpos.com
ServerName demopos.com
127.0.0.1 khpos.com
127.0.0.1 demopos.com
if you call khpos.com:8080 or demopo.com:8080 it should reach your correct virtual hosts.
But: if you call localhost:8080 it will match none of your virtual hosts.
In that case Apache always enters the first virtual host matching the port that you have in your conf file ignoring its server name. That is a strange behavior of Apache - in my opinion a bug. It is exactly what you observe.
For that reason I always place a dummy virtual server in front of all others that can catch all non fitting requests with a dummy message in a simple html file.
Just a hint: you have defined
DocumentRoot "D:/xampp/htdocs/pos"
so there currently is no khpos.com:8080/pos because pos is part of the root unless you create another folder pos below

Virtual Host not pointing properly

I have installed Laravel at C:/Apache24/htdocs/lsapp.
It's working fine with localhost/lsapp/public URL.
What I want to do is instead of above URL I want to access it by mak.org on my local machine.
For that I did following changes
Edited C:/Apache24/conf/extra/httpd-vhosts.conf with below lines:
<VirtualHost *:80>
DocumentRoot "C:/Apache24/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/Apache24/htdocs/lsapp/public"
ServerName mak.org
</VirtualHost>
Edited C:/Windows/System32/drivers/etc/hosts with below lines:
127.0.0.1 localhost
127.0.0.1 mak.org
I restarted my apache server.
But when I hit mak.org in browser, instead of accessing "C:/Apache24/htdocs/lsapp/public" it is pointing to "C:/Apache24/htdocs".
I restarted my PC, enabled opcache.enable=0 in php.ini still not getting desired outcome.
Can anybody help me on this?
What or where am I missing?
The issue resolved by enabling below in httpd.conf file of Apache:
Include conf/extra/httpd-vhosts.conf

Virtual hosts not working on MAMP

I am running into virtual hosts setup issues on MAMP. Here is my vhosts config
NameVirtualHost *
<VirtualHost *>
ServerName dev.local.com
DocumentRoot “/Applications/MAMP/htdocs/local”
</VirtualHost>
<VirtualHost *>
DocumentRoot /Applications/MAMP/htdocs
ServerName localhost
</VirtualHost>
Here is my hosts file
127.0.0.1 localhost
127.0.0.1 dev.local.com
now when visiting localhost and dev.local.com both are pointing to index of local directory. I tried various config setting in vhosts file but none is working. I am on MacBook Pro 10.10
When I first test virtual host (example.dev) I added two slightly different index.php files its directry and to localhost directory (/htdocs). My virtual host would redirect to locahost, I would know because the index.php would be the one in /htdocs. Similar to what user6166 said, I changed the code below to match the 8888 and it worked! I test example.dev:8888 and it works.
NameVirtualHost *:8888
<VirtualHost *:8888>
ServerName dev.local.com
DocumentRoot /Applications/MAMP/htdocs/local
ServerAlias dev.local.com
</VirtualHost>
<VirtualHost *:8888>
DocumentRoot /Applications/MAMP/htdocs
ServerName localhost
</VirtualHost>
Then to remove 8888 change above back to 80 and MAMP preferences to:
Apache Port:80
Nginx Port:8888
mySQL Port:3306
Then inside httpd.conf change below to 80:
Listen 8888
ServerName localhost:8888
Hope that helps someone, it definely fixed my problem!
I didn't find any of the answers useful, so if other suggestions don't work for you:
Consider that the virtual hosts need to be correctly enabled/included by uncommenting
Include conf/extra/httpd-vhosts.conf in C:\MAMP\conf\apache\httpd.conf and NOT in C:\MAMP\bin\apache\conf or C:\MAMP\bin\apache\conf\original .
There're multiple locations that have MAMP configuration, make sure to uncomment that line in the correctly located file.
Changed the hosts file like this -
NameVirtualHost *:80
<VirtualHost *:80>
ServerName dev.local.com
DocumentRoot /Applications/MAMP/htdocs/local
ServerAlias dev.local.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /Applications/MAMP/htdocs
ServerName localhost
</VirtualHost>
Enable virtual host in the right httpd.conf
Open MAMP > File > Edit template > Apache > httpd.conf
edit or add:
# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
edit mamp httpd.conf
I had a similar issue with MAMP Pro 5 (after updating from version 4). One of my custom host with aliases was returning a 404 NOT FOUND error.
After a LONG troubleshoot, make sure to add the domain in the alias list.
MAMP 4
host:
test.co
alias:
sub.test.co
Becomes in MAMP 5:
host:
test.co
alias:
sub.test.co
test.co
Hope they'll get that fixed and that it helps someone!
Try to configure MAMP ports by this way:
MAMP
Preferences
Ports
Apache port: 80
Nginx port: 8888
I've had the same port values and after configurating it started working.
Open the main Apache configuration file, httpd.conf, which is located at
Applications/MAMP/conf/apache/httpd.conf
and Remove the hash (pound) sign from the beginning of the line that begins with Include:
Virtual Hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
I'm not an apache expert. But I had the same problem. I think my DNS doesn't resolve my URL.
When I ping exampl.dev everything looks fine, but when I enter example.dev in the browser I get an error. I always have to add http:// in front of the url.

Hosting two websites from the same webserver

On my webserver, I want to serve several websites just based on domain name.
For example, I want a webserver that will serve "mycoolsite.com" and "badstuff.org".
I pointed both sites at the same IP address. In httpd-vhosts, I made two entries:
<VirtualHost *:80>
DocumentRoot /www/mycoolsite
ServerName www.mycoolsite.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/badstuff
ServerName www.badstuff.org
</VirtualHost>
But when I go to badstuff.org, I get served mycoolsite.com! Why is this happening?
Apache Doc
I also know that when I use MAMP, I have to adjust my "hosts" file too. Is this relevant?
Have you added the NameVirtualHost directive before the vhosts declaration ?
NameVirtualHost *:80
<VirtualHost *:80>
...
</VirtualHost>
You may want to check your configuration by command:
$/usr/local/apache2/bin/httpd -S
If everything is OK, try to check again by restarting the server.

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.