After reading through various tutorials [1] I still can't get my VirtualHost settings to work as desired. I'm getting a 403 Forbidden when I try to use a VirtualHost with a directory below my user directory as its DocumentRoot.
What I've done so far
Created file /etc/apache2/sites-available/workspace with following content:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName project-site
DocumentRoot /home/user/Workspace/project/site
</VirtualHost>
Edited file /etc/hosts now yielding:
127.0.0.1 localhost
127.0.1.1 my-machine
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
# VirtualHosts added by me
127.0.0.1 project-site
Enabled virtual hosts using sudo a2ensite workspace
Restarted Apache using sudo services apache2 restart
Tried opening http://project-site and http://project-site/test.html (where test.html is present in /home/user/Workspace/project/site/) in my webbrowser
What happens
Restarting Apache I get the following messages on the command line:
* Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Sun May 13 10:33:37 2012] [warn] NameVirtualHost *:80 has no VirtualHosts
[ OK ]
Opening either http://project-site or http://project-site/test.html a "403 Forbidden" is served.
What should happen
I'd like to have the contents of /home/user/Workspace/project/site being served when I browse to http://project-site.
What I learned so far
From reading similar questions on this site I learned that this is probably a permission problem [2]. Files in /home/user/Workspace/project/site might not be readable by www-data. But how do I know or correct this?
Furthermore .htaccess files were mentioned [3] being located in
/home/.htaccess
/home/user/.htacces
[...]
/home/user/path/to/project/.htaccess
and possibly not readable. I never created them, I don't want them, will I need them?
The second answer to another question [4] made me use NameVirtualHost responsible for the warning on restart of Apache. Is it necessary and if, how do I use it properly?
Any help is much appreciated! Tell me, if you need to know anything else to locate the problem.
Ressources
http://www.thegeekstuff.com/2011/07/apache-virtual-host/, http://httpd.apache.org/docs/2.2/vhosts/name-based.html, http://mintarticles.com/read/software-articles/multiple-virtual-hosts-in-xampplampp-in-ubuntu,977/, http://www.pgorecki.pl/content/virtual-host-na-localho%C5%9Bcie-apache-ubuntu, ...
Apache VirtualHost 403 Forbidden
Ubuntu, Apache, virtualhost and Access forbidden
VirtualHost configuration
I found the following solution, not satisfying me, but solving my primary problem. Indeed it is about permissions like suggested in [1]. My /home/user directory was not accessible to the webserver. In order to grant minimal possible permissions I used
chmod 701 /home/user
to make it accessible. Additionally I recursively gave group ownership to www-data for the webroot of the virtual host like recommended in [2], but I'm not sure, whether this is necessary.
sudo chown -R user:www-data /home/user/Workspace/project/site
sudo chmod -R g+s /home/user/Workspace/project/site
I'm going to ask for a more elegant solution in a separate question.
Regarding the other problems mentioned, I found out the following with the help of [3] besides other resources:
It is not necessary and may cause an error to have NameVirtualHost *:80 in the virtual hosts description, if it appears in one of apaches other configuration files.
To let apache know about its fully qualified domain name being localhost one creates a file /etc/apache2/conf.d/fqdn with content ServerName localhost.
https://stackoverflow.com/a/7576526/948404
https://stackoverflow.com/a/9133067/948404
https://help.ubuntu.com/community/ApacheMySQLPHP
Related
On my debian/apache server at http://localhost I'm redirected to my api on port 3000 (this is ok)
Now I would like to open another port (8090), in http://localhost:8090 redirected to /var/www/html/
How to make?
Find the default virtual host conf file by running
ls /etc/apache2/sites-available/
There should be a file called deault.conf, or similar. We want to edit this file
sudo nano /etc/apache2/sites-available/default.conf
Make sure that apache actually is listening to your port 8090 by adding, to the top of that document
Listen 8090
Change the rest of the conf file to match your site, so it may look something like this
Listen 8090
<VirtualHost *:8090>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/
# Other directives here
</VirtualHost>
Save the file with a different name in the same folder. The files must end with ".conf". Add the virtual host to enabled sites by running
sudo a2ensite virtual_host_file_name.conf
replacing "virtual_host_file_name.conf" with the name of the file you select in the previous step.
Then restart the apache server
sudo service apache2 reload
It seems like you're only interested in accessing it from localhost, but if you want to access it remotely you might need to check your firewalls.
I have an Ubuntu server in AWS that is running multiple application servers -- a Wildfly serving up some pages and two Tomcats running a separate app.
I am trying to get subdomains working.
I have DNS's set up to point subdomain1.example.com, subdomain2.example.com. That works fine.
Wildfly is listening on port 80 (I think?), the Tomcats are listening on 8080 and 8090. The goal is to have www.example.com go to Wildfly, subdomain1.example.com go to Tomcat : 8080 and subdomain2.example.com go to Tomcat : 8090
I've found numerous posts that talk about setting up virtual hosts in Apache that should solve my problem. But I keep getting sent down rabbit holes. Some suggest adding to /opt/bitnami/apache2/bin/httpd.config and some suggest putting it in /opt/bitnami/apache2/sites-available/subdomain1.example.com.conf
My first issue: I don't think that Apache is even running. I was under the impression that Apache was baked into Wildfly, but when I execute:
service apache2 status
I get:
apache2.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
Running sudo service --status-all also doesn't show it running so I think that it is not. It seems to be installed (Bitnami stack) in /opt/bitnami/apache2
Do I have to turn Apache on as part of Wildfly (and how to turn it on)? If I do, then I would assume that Wildfly is no longer getting traffic.
Second - my research tells me I need i need to enable proxy and proxy_http using a2enmod and a2ensite but I don't have these. Research suggests that all Ubuntu's will have those scripts... do they get created if I turn on Apache?
Sorry for all the noob questions.... I'm a developer without a DevOps guy. This seems like it would so common it would be baked in or there would be a definite solution that I am probably missing.
For those looking for something similar, here is the solution that worked for me.
My server is a Wildfly-Apache2-MySQL AMI image on AWS. I did not need to use a2enmod nor a2ensite as my research suggested. It seems many of those modules are already enabled by the pre-built image.
NOTE THESE INSTRUCTIONS ARE BITNAMI AWI SPECIFIC - YOUR FLAVOR CONFIGURATION MAY BE SLIGHTLY DIFFERENT
To have a subdomain point to a simple Apache text site (yada.example.com):
Create a directory in ~/stack/apache2/htdocs called yada
Add an entry to the virtual hosts configuration file (sudo nano /opt/bitnami/apache2/conf/extra/httpd-vhosts.conf)
<VirtualHost *:80>
ServerAdmin info#example.com
DocumentRoot "/opt/bitnami/apache2/htdocs/yada"
ServerName yada.example.com
ErrorLog "logs/yada-subdomain-error-log"
CustomLog "logs/yada-subdomain-access-log" common
</VirtualHost>
Modify the Apache configuration file to include the virtual hosts. (sudo nano /opt/bitnami/apache2/conf/httpd.conf):
...snip...
# Supplemental configuration
#
# The configuration files in the conf/extra/ directory can be
# included to add extra features or to modify the default configuration of
# the server, or you may simply copy their contents here and change as
# necessary.
...snip...
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
# ADDED THE ABOVE LINE
...snip...
Restart Apache (sudo /opt/bitnami/ctlscript.sh restart apache)
To make it point to a Tomcat server, add this to the httpd-vhosts.conf:
<VirtualHost *:80>
ServerAdmin info#example.com
ServerName yada.example.com
ProxyPreserveHost On
# setup the proxy
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://localhost:8090/
ProxyPassReverse / http://localhost:8090/
</VirtualHost>
Your port may differ.
FYI, I found this helpful: https://docs.bitnami.com/virtual-machine/components/apache/#how-to-configure-your-web-application-to-use-a-virtual-host
Good luck and shout out to #stdunbar for his guidance.
I had an issue last night where MAMP just refused to connect to the Apache server(unsure whether this has something to do with my issue). I decided to uninstall and reinstall. I was able to connect once again, however, when I added my virtual host to the httpd-vhosts.conf file in my MAMP folder, and navigate to it I get brought to a 'It works!' page. (I also realised I get this page by typing localhost even without running MAMP?)
Below are some of my files
httpd.conf(in MAMP)
//Uncommented line below
# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
httpd.conf(in MAMP)
NameVirtualHost *:80
<VirtualHost *:80>
ServerName portfolio
DocumentRoot '/Applications/MAMP/htdocs/portfolio'
</VirtualHost>
<VirtualHost *:80>
DocumentRoot '/Applications/MAMP/htdocs'
ServerName localhost
</VirtualHost>
/private/etc/hosts
##
# Host Database
# localhost is used to configure the lookback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 portfolio
This is a copy paste of what I had before which worked 100%, unsure what happened between MAMP stopping working, the uninstall and reinstall. Is there an issue with apache somehow overwriting something? Really out of my depth here with this issue. Is there somewhere else I should be looking to debug this?
For reference, localhost:8888 & localhost:8888/portfolio work as expected, localhost/ & portfolio/ don't, brings me to the 'It works!' page. Before this issue I was able to do 'localhost/phpmyadmin' to bring me to phpmyadmin and 'localhost/portfolio' to bring me to that directory, but neither of those work either. I've been wracking me brain for hours over this, watching tutorials and reading other answers but to no avail.
Anyone have any idea why this is occuring? Any help would be greatly appreciated.
So I eventually figured it out if anyone else has the same issue. I had forgotten previously that I had my localhost running on port 80. However when I tried that before my apache server wouldn't start on MAMP, the reason being was due to port 80 being used by /private/etc/apache2, so I used the answer to this question
https://superuser.com/questions/986775/how-can-i-remove-apache2-that-i-have-installed-in-mac-os-x
to remove apache. (Alternatively I guess you could just change the port number it listens to in the httpd.conf files?) I then changed my MAMP to listen to port 80 and this fixed my problem. Hope this helps anyone else with same issue
I am on Windows 8 and just now installed Wamp 2.5 (Apache 2.4.9) at C:/wamp to test my code locally. I have my source code repository at D:/workpace/project1 which I manage using GIT (GIT is one of the reasons I don't want to disturb its location).
After Installing Wamp, I just went on to enable virtual hosts by uncommenting the following line in httpd.conf.
#Include conf/extra/httpd-vhosts.conf
Then I headed to conf/extra/httpd-vhosts.conf created its backup and created the virtual host.
<VirtualHost *:80>
ServerAdmin admin#example.com
DocumentRoot "D:/workspace/project1/"
ServerName project1
ServerAlias p1
ErrorLog "logs/project1(local)-error.log"
CustomLog "logs/project1(local)-access.log" common
<Directory "D:/workspace/project1/">
Require all granted
</Directory>
</VirtualHost>
Also edited the hosts file and added the necessary lines.
127.0.0.1 project1
127.0.0.1 p1
The problem is that I get 403 Forbidden error not just when I access project1/ and p1/, but also when I access localhost/.
When I disable httpd-vhosts.conf in httpd.conf by commenting out,
Include conf/extra/httpd-vhosts.conf
I am able to access localhost/ but as expected, project1/ and p1/ too resolve to localhost/.
Surprisingly, when I re-enable httpd-vhosts.conf in httpd.conf and restore the backup of original(unchanged) httpd-vhosts.conf, I still get 403 (Forbidden) even on localhost/. But again when I disable httpd-vhosts.conf, localhost/ comes to normal.
It is furthermore surprising to note that If I change DocumentRoot to a dummy folder within c:/wamp/www, the story is the same. So this is not just happening when DocumentRoot is outside c:/wamp/www.
I feel that I have something extra to enable because there is no chance I have messed up anything as this is a fresh installation and I have made no changes except the ones above.
What may be the reason Apache is not getting along with virtual hosts?
There are a few things that you have not taken into account.
When you create Virtual Hosts Apache ignores the host defined in httpd.conf so you also need to create a Virtual Host for localhost. This explains why you cannot get to localhost when you have activated Virtual Hosts.
Apache is IPV4 and IPV6 aware, so when you create your domain names in the HOSTS file you need to do so for both the IPV4 and IPV6 stacks. So you would need to have a HOSTS file like this :-
#IPV4 Stack
127.0.0.1 localhost
127.0.0.1 project1
#IPV6 Stack
::1 localhost
::1 project1
The browser makes some arbitrary decision on whether to use the IPV4 stack or the IPV6 stack. Wish I understood why and for what reason it makes this decision better, but basically when you enter a domainname, the browser, or the networking stack, picks IPv4 or IPv6 for your first contact to a domain and then sticks to that decision, but it could use either.
Here is a post that should help you create Virtual Hosts
I am a beginner to Apache and have been trying to create virtual hosts but I come across a very odd issue. When the site is requested using the IP defined in the configuration, the virtual host works perfectly but when the name of the server is used it does not work.
Here is the configuration file which is an included file:
Listen 80
NameVirtualHost 192.168.1.5
<VirtualHost 192.168.1.5>
ServerName host1.localhost
DocumentRoot "C:/Program Files (x86)/Apache Group/Apache2/virtualHost1"
</VirtualHost>
In the browser I go to 192.168.1.5 and the index file for the Virtual Host appears but when I go to host1.localhost it doesn't work.
Any help is very appreciated, good day to all.
First you should try to see if your computer resolve host1.localhost hostname.
May be just try to ping it in your console: ping host1.localhost
If your computer is unable to resolve host1.localhost, as I suppose, then try to add it in your hosts file.
Hint: you'll find hosts file in C:\Windows\System32\drivers\etc directory
What do you mean by "it doesn't work".
1)Check your DNS settings, do you have record for host1.localhost pointing to 192.168.1.5?
2)Try using ServerAlias also
3)Check if there is another declaration for hosts1.localhost (by another ServerAlias)
I guess the most likely reason is 1)