I've developed virtual hosts in my mac but instead of showing the project its showing "it works".
I have a java application, this is my httpd-vhosts.conf:
<VirtualHost *:8080>
DocumentRoot "/Users/lalarukh/data/code/prestige-apis"
ServerName labraize.in
<Directory "/Users/lalarukh/data/code/prestige-apis">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
etc/hosts file:
127.0.0.1 labraize.in
Uncommented the required lines also in httpd.conf file.
For testing purpose I made a directory in my server folder named test. And made index.html file inside. And called it in hosts as http://test.com But it also returned "It works".
Means that apache vhosts can't get inside the code directory that's why its not working.
vhosts showing 'it works' instead of project pages.
The vhost is listening on port 8080 and not the default 80 so if you want to reach the correct vhost, you need to add :8080 at the end of the URL so in theory: http://labraize.in:8080 should work.
Related
I'm trying to set up a local development environment for a PHP project. The project is placed in the htdocs folder, and i wanna be able to access it on a virtual host environment so all the links and so on works, and treats it as the root directory.
So, here is what i have done:
C:\Windows\System32\drivers\etc
hosts
127.0.0.1 bakeboss.test
C:\xampp\apache\conf\extra
httpd-vhosts
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\bakeboss"
ServerName bakeboss.test
<Directory "C:\xampp\htdocs\bakeboss">
</Directory>
</VirtualHost>
Apache starts up fine, but if i try to go to (in my browser):
www.bakeboss.test
NOTHING happens - cannot find it, cannot connect. If i go to localhost/bakeboss it works, but obviously not the way i want it.
What am i missing here?
I am not sure if this is a repost but I couldn't find a solution.
I have an application setup in my local environment which the name I added in my hosts file (C:\Windows\System32\drivers\etc) as follows,
127.0.0.1 skeletonpage.lk
Also I added a record in httpd-vhosts.conf as below.
<VirtualHost *>
DocumentRoot "C:/xampp/htdocs/skeleton/public"
ServerName skeletonpage.lk
<Directory "C:/xampp/htdocs/skeleton/public">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
When I run the application on browser I can only load the homepage with the port number tagged with the site name. Ex: http://skeletonpage.lk:83/
I have both XAMPP and WAMP in my machine and my site runs in XAMPP for which the port 83 is given, If I remove :83 it loads the homepage of wamp server which has port 80.
I tried removing and modifying above code snippet but still cant get rid of port 83. I know this is something simple, but would be glad if someone can help.
I modified as <VirtualHost *:83> also <VirtualHost 127.0.0.1:83> and restarted XAMPP also modified NameVirtualHost *:83 but no use.
I have asked a similar question before
Restrict access to directories through ip address
at that time the problem was solved for apache 2.2. Recently I re-installed the OS (to Debian 8) and it comes with apache 2.4.
I want to restrict access to files - when the request comes "by" IP. Mainly if in the browser I try to open http://192.168.252.178/test/image.jpg it should show error - 403 forbidden. Directory test is in www directory of apache. However I should be able to access that image if I type http://www.example.com/image.jpg - considering that example.com points to that test directory.
With apache version 2.2 I would simply put this lines in my default site config file - and the problem was solved
<Files ~ ".+">
Order allow,deny
Deny from all
</Files>
Now, trying the same thing does not work: I am getting 403 forbidden even if I try to open any site by the domain name.
Considering the changes in 2.4 I also tried this, but again getting the the same 403 forbidden when trying to open some site.
<Files ~ ".+">
Require all denied
</Files>
My goal is to prevent any kind of access to directories and files - if they are being accessed through ip address. I have also this lines in my default site's config to prevent the directory access and this works fine.
<Directory /home/username/www>
Options -Indexes
AllowOverride All
Require all granted
</Directory>
So, the question is - how to prevent file access through IP address. Also I need to achieve this by apache config, by htaccess is not a solution for me. And I need to achieve this for all the directories/files inside www recursively, so specifying the exact file names and/or directories is not a solution either.
Thanks
When you use name based virtual hosts, the main server goes away. Apache will choose which virtual host to use according to IP address (you may have more than one) and port first, and only after this first selection it will search for a corresponding ServerName or ServerAlias in this subset of candidates, in the order in which the virtual hosts appear in the configuration.
If no virtual host is found, then the first VHost in this subset (also in order of configuration) will be choosen. More.
I mention this because it will be important you have only one type of VirtualHost directive:
<VirutalHost *:80>
or
<VirtualHost 123.45.67.89:80>
I'll use the wildcard in the example.
You need a directory like /var/www/catchall with a file index.html or similar, as you prefer.
<VirtualHost *:80>
# This first-listed virtual host is also the default for *:80
# It will be used as the catchall.
ServerName 123.45.67.89
# Giving this DocRoot will avoid any request based on IP or any other
# wrong request to get to the other users directories.
DocumentRoot "/var/www/catchall"
<Directory /var/www/catchall>
...
</Directory>
</VirtualHost>
# Now you can add as usuall the configuration for any other VHost you need.
<VirtualHost *:80>
ServerName site1.com
ServerAlias www.site2.com
DocumentRoot "/home/username1/www"
<Directory /home/username1/www>
...
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName site2.com
ServerAlias www.site2.com
DocumentRoot "/home/username2/www"
<Directory /home/username2/www>
...
</Directory>
</VirtualHost>
Debian specific :
For Debian, you ideally put one VHost configuration per file, and put the file in the /etc/apache2/sites-available directory.
Name the files as you like, only the file containing the catchall vhost should be named something like 000-catchall, because they will be read in alphabetic order from the /etc/apache2/sites-enabled directory.
Then you disable Debian's usual default site :
a2dissite 000-default
and you enable the new catchall site and the other VHosts if needed :
a2ensite 000-catchall
An ls /etc/apache2/sites-enabled command should show the catchall as the first of list, if not change its file name so that it will always be the first. Restart Apache: service apache2 restart
Of course you could do all this changes in the original default VHost config file, but I usually prefer keep an original model.
I have a problem in creating my virtual using WampServer. In the office I can create and run a virtualhost properly. But when I tries to create in my laptop. I t redirects to the localhost page of my wampserver. It displays the default page of wampserver. Here's what I did.
First I move my project in this directory: - C:\Users\jerielle0214\Documents\Chelle\hallohalloalliance
Second is I add the virtual host in apache (C:\wamp\bin\apache\apache2.2.22\conf\extra\httpd-vhosts.conf)
<VirtualHost *:80>
ServerName chelle.hallohalloalliance.com
ServerAlias chelle.hallohalloalliance.com
DocumentRoot "C:/Users/jerielle0214/Documents/Chelle/hallohalloalliance/"
<Directory "C:/Users/jerielle0214/Documents/Chelle/hallohalloalliance/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
And I include my virtualhost in the Windows hosts file. I add this in the bottom of the hosts file
127.0.0.1 chelle.hallohalloalliance.com
Last I restarted the wampserver and I access my page using chelle.hallohalloalliance.com but it only redirect my page to default wamp page. I don't know where's the error. Please help me guys thanks.
Apache will fallback to the first host it was correctly told about when there is a problem with your VHOST definitions.
Did you uncomment this line in the httpd.conf file so Apache includes your vhost definition?
#Include conf/extra/httpd-vhosts.conf
just remove the #.
Also when you change the hosts file you need to reboot or refresh the DNS Cache for the changes to be visible to windows. To refresh the cache do this from a command window ( run as Administrator )
net stop "DNS Client"
net start "DNS Client"
I have configure httpd.conf and httpd-vhosts.conf, when I active the web sharing the virtualhost is useful, but when I close web sharing and start apache, the virtualhost doesn't work
Here is my virtualhost config
<VirtualHost *:80>
DocumentRoot "/Users/lch/Sites"
ServerName myhome.com
</VirtualHost>
<Directory "/User/lch/Sites">
Options None
Allow from all
</Directory>
And, here is error short-cut:
I am a newer for Mac OS, and I come from china.
Thank you for read my question.
Two things to check:
Is the include for httpd-vhosts.conf uncommented in httpd.conf? I believe it's commented out by default.
Have you added myhome.com to your hosts file? Make sure you've got the following entry in /etc/hosts: 127.0.0.1 myhome.com