I am trying to set up a VirtualHost for some web projects I have undergoing. To do this, I have a folder in my User account ~/Projects/ in which I place all of my projects and I want to remain like that. When I tried to create a VirtualHost under ~/Projects/aproject/web Apache denies me access.
After some tries, I discovered that if I put the project under other directory than the user space (~/....) the Apache lets me create the VirtualHost that otherwise denies access.
I think this problem has to do with the UserDir directive which I think prevents access to every folder in user space but the ones listed in the UserDir - in my case it is UserDir Sites - but I do not know how to circumvent this and allow Apache to serve custom user space folders. Any ideas?
The directives in httpd.conf that I am trying are this ones:
<VirtualHost *:80>
DocumentRoot "/Users/myuser/Projects/myproject/web"
ServerName www.myproject.local
</VirtualHost>
<Directory "/Users/myuser/Projects/myproject/web">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
I also have set the directive NameVirtualHost *:80 in httpd.conf.
And created the appropriate directive in /etc/hosts: 127.0.0.1 www.myproject.local.
Best regards.
You may need to alter the config for your user:
users/{username).conf
Then all AuthConfig to AllowOverride
Related
I'm trying to create VirtualHost for a different port number with below code, but when I try to access that port number "domain: port" I receive "ERR_CONNECTION_REFUSED" error on browser.
Steps, what I do
First editing http.conf, created for the related domain via Plesk
I am writing these codes
Restart Apache
Also I add that port number on httpd.conf. (Listen: port) but at this point I receive "Internal Server Error"
What do I use:
Plesk 12,
Apache/2.2.15 (Unix),
Ngnix (Reserve proxy)
<VirtualHost IP:8324>
DocumentRoot "/var/www/vhosts/httpdocs"
ServerName "domain:8324"
ServerAlias "www.domain.com"
ServerAlias "ipv4.domain.com"
UseCanonicalName Off
<Directory /var/www/vhosts/httpdocs>
DirectoryIndex index.php
Options +Indexes +FollowSymLinks +MultiViews +Includes
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
What am I missing? Thank you
I think you can do that using a custom template for a specific vhost.
You should check these two links. The might put you on the right track:
https://docs.plesk.com/en-US/12.5/advanced-administration-guide-linux/virtual-hosts-configuration/changing-virtual-hosts-settings-using-configuration-templates/example-changing-default-apache-ports.68800/
https://docs.plesk.com/en-US/onyx/advanced-administration-guide-linux/virtual-hosts-configuration/changing-virtual-hosts-settings-using-configuration-templates.68693/
Just so you know, any manual changes that you do in the httpd.conf file (from a ssh console for example, at the next plesk update or when you add/delete an account, they will be overwritten since Plesk is regenerating the httpd.conf file)
This should be a very simple question to answer for people who knows apache.
I have an Ubuntu computer which I use as my server. I have worked with apache several times before, but never experienced this issue.
My owncloud.conf file in the sites-enabled folder looks like this:
1 <VirtualHost *:80>¬
2 ServerName owncloud¬
3 DocumentRoot "~/mybook/ownCloud"¬
4 <Directory ~/mybook/ownCloud/>¬
5 Options None¬
6 Order deny,allow¬
7 Allow from all¬
8 </Directory>¬
9 </VirtualHost>
But after enabling the site and restarting apache, I'm getting this error:
AH00112: Warning: DocumentRoot [/etc/apache2/~/mybook/ownCloud] does not exist
I've been looking, and I cannot seem to find where it's set that "/etc/apache2/" should be leading default path to all set document roots of the site config files.
Does anyone know how I can remove this default setting?
Forget the comment I made regarding Mac, what you have above will not work. If you installed Apache on Ubuntu and accepted the defaults the docroot is /var/www and I am assuming you want your /mybook/ownCloud mapped to docroot. That is how you should do it because the httpd will run with group permissions to the real docroot. That can be done using an alias as I have below. Look at the bottom, but also note that I specified the correct default docroot in the beginning before I mapped anything. You can change the docroot but you will have to make sure the permissions on the new directory structure are set correctly.
I aliased your /mybook/ownCloud/ to ownCloud. Also, I have other directives that I removed from the sites-enabled code below for clarity.
BTW, I have personally never used tildes within an Apache conf file like you have above, it could be confusing during startup.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Alias /owncloud/ "/mybook/ownCloud"
<Directory "/mybook/ownCloud">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
EDIT:
There are other ways to configure a VHost, but this is basically how it is done. You no longer set a server wide docroot declaration in httpd.conf. The /etc/apache2/ path is the server home and in the absence of a docroot declaration in your sites-enabled it may have defaulted to Server Home when httpd started.
I am unable to stop apache from creating directory listings when using the server IP address. I have tried editing the relevant site-available files as follows;
<VirtualHost *:80>
JkMount /* default
ServerName example.co.uk
ServerAlias www.example.co.uk
ServerAdmin me#example.co.uk
DocumentRoot /var/www/example.co.uk/public_html
ErrorLog /var/www/example.co.uk/logs/error.log
CustomLog /var/www/example.co.uk/logs/access.log combined
<Directory /var/www/example.co.uk/public_html>
Options -Indexes
</Directory>
</VirtualHost>
...but the public_html folder contents are being listed if I access the server using a url of this format;
http://192.168.1.99/example.co.uk/public_html
I have also tried to amend the apache config file at /etc/apache2/apache.conf to include the following;
<Directory />
Options -Indexes
</Directory>
..but no joy.
I am using Tomcat, and I need my WEB-INF folder to deny access. It doesn't, and so any .class files can be downloaded.
Does anyone know how I can fix this?
thanks
This sounds a little weird. Do you have an Apache HTTPD in front of an Apache Tomcat Server?
In this case the Apache HTTPD must not point to a directory where the Apache Tomcat files reside! The communication between both can be seen more as a proxy rather than a plugin.
We have some good experience using mod_proxy_ajp for this purpose. But if you are able to download .class files and (panic mode on) the web.xml (panic mode off) something is terribly wrong.
This means that it will not reach your VirtualHost settings, but default virtual host settings.
You have 2 options (at least):
1, put .htaccess file to your directory for which you want to restrict listing
2, Setup you IP based virtual host with similar settings as your name-based vhosts
You said that you put
<Directory />
Options -Indexes
</Directory>
You should have Location instead of Directory there
What if you add /* to the end?
<Directory /var/www/example.co.uk/public_html/*>
Options -Indexes
</Directory>
Update:
Or try to add the entry outside the VirtualHost directive.
I have an Ubuntu dedicated server, and I have 2 domain names. The first one is related to the directory '/var/www/' and the second one is too, I didn't know how to associate the second one to another directory like '/var/www/site2/'
Can you help me ?
Thank you !
To host multiple domains on the same server with different directories of their own, you need to use the VirtualHost config directive. Inside each one you can specify their own set of configurations (by default the configuration file is stored at /etc/apache2/sites-enabled/000-default.conf):
NameVirtualHost *:80
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/site1
<Directory /var/www/site1>
Options -Indexes
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName another-example.com
DocumentRoot /var/www/site2
<Directory /var/www/site2>
Options +Indexes
</Directory>
</VirtualHost>
The first one lives in /var/www/site1 and has directory indexing turned off. The other is in /var/www/site2 and has directory indexing turned on. You can specify pretty much most configs to be virtualhost specific - ie, custom logging, use of modules such as php or perl, and ServerAlias, among much more. See http://httpd.apache.org/docs/2.2/mod/core.html#virtualhost for more details.
I have on my machine wampp server installed that I use to run php applications.
There are many folder in the htdocs with inside my projects and I can see those in the browser at this url: localhost/folder-name/.
I'd like to see every project in a custom url like: dev.name-folder.com
With IIS is very easy to do that, can someone explain how do that with Apache, using wampp server?
Thanks.
You can change your C:\Windows\System32\drivers\etc\hosts file to map domain names like dev.name-folder.com to your local system. (Otherwise you'll have to use a DNS server).
To configure a vhost in apache create a file for each domain/project you'd like to serve:
<VirtualHost *:80>
ServerAdmin email#domain.tld
ServerName domain.tld
DocumentRoot /var/www/htdocs/domain.tld/html
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/htdocs/domain.tld/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
ServerName is the domain name you'd like to serve your files under. DocumentRoot must be set to the absolute path to your files (here taken from a linux system).