403 Forbidden Error after adding Virtual Hosts
Posted by: xPrinceShayjayx (---.cable.mindspring.com)
Date: February 14, 2016 03:51PM

Hello, I recently followed the tutorial for creating virtual hosts here: [forum.wampserver.com]

After going through all those steps, however, and making sure that I did every step completely, when I attempt to visit my server from the outside (via my IP adress or domain name, NOT from Localhost), I get a "forbidden: You don't have permission to access / on this server" error. How can I make this go away?

1. Windows 10 62 bit
2. WampServer 2.5
3. Apache/2.4.9 (Win64)
4. PHP 5.5.12
5. MySQL 5.6.17
6. WampServer icon is GREEN
7. Only 2 active lines with localhost in them: "127.0.0.1 localhost" is one, the other is "::1 localhost"
8. I have access to localhost
9. I have access to PHPMyAdmin
10. Error message: "forbidden: You don't have permission to access / on this server"
11. No antivirus used, firewall is Windows Firewall
12. Path to wamp: C:\wamp\

Options: ReplyQuote
Re: 403 Forbidden Error after adding Virtual Hosts
Posted by: RiggsFolly (---.dynamic.dsl.as9105.com)
Date: February 14, 2016 06:39PM

Hi

Please show us your httpd-vhosts.conf file.

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: 403 Forbidden Error after adding Virtual Hosts
Posted by: xPrinceShayjayx (---.cable.mindspring.com)
Date: February 14, 2016 08:02PM

Here is the file, copy and pasted word for word:

# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:[httpd.apache.org];
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
DocumentRoot "c:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "c:/wamp/www">
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/stuysmile"
ServerName stuysmile
<Directory "c:/wamp/www/stuysmile">
AllowOverride All
Require local
</Directory>
</VirtualHost>

Options: ReplyQuote
Re: 403 Forbidden Error after adding Virtual Hosts
Posted by: RiggsFolly (---.dynamic.dsl.as9105.com)
Date: February 14, 2016 08:26PM

Ok,

You have not told Apache that it is allowed to be connected to from anywhere other than the local machine as all you have said is "Require local"


So change this host definition to allow access from the internet


<VirtualHost *:80>
    DocumentRoot "c:/wamp/www/stuysmile"
    ServerName stuysmile
    <Directory "c:/wamp/www/stuysmile">
        AllowOverride All

        Require all granted
    </Directory>
</VirtualHost>


However using the domain name `stuysmile` will probably not work when used from outside of your network `stuysmile` is not a valid domain name and DNS Servers will not know anything about it.

If you use your WAN IP Address Apache will attempt to connect you to the default domain which is always the first one in the httpd-vhosts.conf file, so localhost, and that will of course be rejected as it is only allowed to be connected to by the local machine "Require local"

You would be best advised to either buy a real domain name or geta Dynamic Domain name fro somewhere like NO_IP or DYNDNS and then change the Virtual Host defeinitions to


<VirtualHost *:80>
    DocumentRoot "c:/wamp/www/stuysmile"
    ServerName stuysmile.dyndsn.net    
    <Directory "c:/wamp/www/stuysmile">
        AllowOverride All

        Require all granted
    </Directory>
</VirtualHost>

"stuysmile.dyndsn.net` is an example only, there are various options available but that is up to you to pick one.


One way of testing things would be to change the order of your definitions, this would make use of the way Apache picks the default VH if a match cannot be found like this



<VirtualHost *:80>
    DocumentRoot "c:/wamp/www/stuysmile"
    ServerName stuysmile
    <Directory "c:/wamp/www/stuysmile">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>


<VirtualHost *:80>
    DocumentRoot "c:/wamp/www"
    ServerName localhost
    ServerAlias localhost
    <Directory "c:/wamp/www">
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: 403 Forbidden Error after adding Virtual Hosts
Posted by: xPrinceShayjayx (---.cable.mindspring.com)
Date: February 15, 2016 02:06AM

Thank you so much! My server is accessible now from outside.

To expand on this, however, how can I link multiple domain names to different folders on this same server? For example, suppose I have the domain "example.com" linked to the "www" folder of WAMP. Now suppose I buy another domain, "project.com" and I also want to link that to my server, but NOT to the "www" folder (I want this project to be independent of that), but to the folder (C:\wamp\www\project). I have already made "project" a host in httpd-vhosts.conf. What is the next step to link this new domain to this specific folder on my server?

Options: ReplyQuote
Re: 403 Forbidden Error after adding Virtual Hosts
Posted by: RiggsFolly (---.dynamic.dsl.as9105.com)
Date: February 15, 2016 03:06AM

Just create another Virtual Hosts and point it to the new folder. Thats the whole point of Virtual Hosts

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: 403 Forbidden Error after adding Virtual Hosts
Posted by: xPrinceShayjayx (---.cable.mindspring.com)
Date: February 15, 2016 03:32AM

I created a new virtual host, but how can I point the domain to the new virtual host instead of my default ip address?

For example, when I registered my domain name, I told it to point to an IP address: 123.456.789.10. By default, if I type in the domain name into my browser, it will take me to the C:/wamp/www folder on my computer, because that is the default folder for my IP adress. However, I don't want my domain to take me to that default localhost folder (C:/wamp/www), I want the domain to take me to a different folder under my IP address, the folder (C:/wamp/www/project). How can I do that? Will I have to change the A records, change the name servers, etc?

At the moment, I have three different domains that I want to point to three different folders on my server, but no matter what I do, they all point to the same folder (C:/wamp/www, which is localhost) instead of different subdirectories like (C:/wamp/www/project) or (C:/wamp/www/example). How can I change that?

Options: ReplyQuote
Re: 403 Forbidden Error after adding Virtual Hosts
Posted by: RiggsFolly (---.dynamic.dsl.as9105.com)
Date: February 15, 2016 09:58AM

Apache will look at the incoming domain name in the url and match it to one of the Virtual Hosts definitions. If it cannot match the domain name it will use the first in the list.
As the forst in the list is localhost AND SHOULD ALWAYS BE SET TO "Require local" any incorrect domain names, or drive by IP Address texting will get an error and not be allowed access.


<VirtualHost *:80>
    DocumentRoot "c:/wamp/www"
    ServerName localhost
    ServerAlias localhost
    <Directory "c:/wamp/www">
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "c:/wamp/www/stuysmile"
    ServerName stuysmile.com
    ServerAlias www.stuysmile.com
    <Directory "c:/wamp/www/stuysmile">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>


<VirtualHost *:80>
    DocumentRoot "c:/wamp/www/example"
    ServerName example.com
    ServerAlias www.example.com
    <Directory "c:/wamp/www/example">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "c:/wamp/www/project"
    ServerName project.com
    ServerAlias www.project.com
    <Directory "c:/wamp/www/project">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-



Edited 1 time(s). Last edit at 02/16/2016 11:42AM by RiggsFolly.

Options: ReplyQuote
Re: 403 Forbidden Error after adding Virtual Hosts
Posted by: xPrinceShayjayx (---.cable.mindspring.com)
Date: February 16, 2016 04:32AM

Thank you so much! Worked like a charm!

Options: ReplyQuote


Sorry, only registered users may post in this forum.