My server IP + all subdirectories are pointing to Subversion (SVN) - apache

I installed a subversion on my server and it's working properly. All my repositories are located at /var/svn/repo1 /var/svn/repo2 etc... My /etc/apache2/sites-available/svn looks this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName svn.myhostname.com
DocumentRoot /var/svn
<Directory /var/svn/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
<Location />
DAV svn
SVNParentPath /var/svn
AuthType Basic
AuthName "Subversion"
AuthUserFile /etc/subversion/svn-auth
Require valid-user
</Location>
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/svn.error.log
CustomLog ${APACHE_LOG_DIR}/svn.access.log combined
</VirtualHost>
The problem is that when I open a browser and type my IP address or hostname they both point to SVN for some reason. For example, when I type only my IP the browser says "A username and password are being requested by MYIPADDRESS. The site says: "Subversion"". I think the only address that should be pointed to SVN would be svn.myipaddress.com, right??
When I type svn.myipaddress/repo1 it shows the repository normally though.
This causes me hard times as I cannot access my IP and open html/php-files there because it asks for SVN password every time.
Any thoughts on this?

Your initial <VirtualHost *:80> is redirecting all requests on port 80 (the standard http port) to the subversion directories. If you change that to something like <VirtualHost *:3690> then standard web requests should work as normal, though you'll need to add the port when accessing the repositories from the client, i.e. svn co http://repository.url:3690/repo1 in order for subversion commands to work.

Related

Apache VirtualHost configuration & Subversion

I'm trying to configure a sub-domain for my subversion repository.
I have a VH example.fr pointing to my personal website, and I want another VH svn.example.fr to point to the repository.
However, when I try to connect to svn.example.fr, I get the front page of my website...
Here is my Apache configuration file:
<VirtualHost *:80>
DocumentRoot /srv/example.fr
ServerName example.fr
ServerAlias www.example.fr
<Directory /srv/example.fr>
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName svn.example.fr
<Location />
DAV svn
SVNPath /srv/svn/repo
AuthType Basic
AuthName "Subversion repository"
AuthUserFile /srv/svn/repo/conf/passwd
AuthzSVNAccessFile /srv/svn/repo/conf/authz
Require valid-user
</Location>
</VirtualHost>
I don't see any problem here, but I'm sure there is.
Thanks for your help !
EDIT : The configuration file is correct. I should precise that I'm running Apache inside a Docker container. Just after creating the conf file, I restarted Apache by restarting the container. This is not the right way to do it: restarting the container does not restart the server.
So Lazy Badger was right finally, thanks.
This is question for SU
After creating VirtualHost section you have to restart Apache
(Not related to network|Apache config, future trouble) Plain-text /srv/svn/repo/conf/passwd, used by svnserve, can't be used as Apache user-file, i.e. you have to have
...
AuthUserFile /path/to/htpasswd/file
...
DocumentRoot for VirtualHost must be defined, svn.example.fr miss it

VirtualHosts configuration in one file or not?

I'm running a http server on Debian (Apache 2) with one IP address. I have few domains and SVN running on the server as well. At the moment I have configuration that points my domains to the correct folders on my server with VirtualHosts.
I have done all my VirtualHosts configurations only in the file called "/etc/apache2/sites-available/default". Is this the correct way to do it, or should I make a new file for every website I'm running on my server?
At this moment, my VirtuaHosts file (/etc/apache2/sites-available/default) looks like this:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.domain1.com
ServerAlias domain1.com
DocumentRoot /var/www/domain1
</VirtualHost>
<VirtualHost *:80>
ServerName www.domain2.com
ServerAlias domain2.com
DocumentRoot /var/www/domain2
</VirtualHost>
<VirtualHost *:80>
ServerName svn.myhostname.com
DocumentRoot /var/svn
<Directory /var/svn/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
<Location />
DAV svn
SVNParentPath /var/svn
AuthType Basic
AuthName "Subversion"
AuthUserFile /etc/subversion/svn-auth
Require valid-user
</Location>
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/svn.error.log
CustomLog ${APACHE_LOG_DIR}/svn.access.log combined
</VirtualHost>
There is no 'correct' way. You could also make an extra file for every Vhost. I for example have all my VHosts in /etc/apache2/httpd.conf and included it via Include httpd.conf in /etc/apache2/apache2.conf.
But if you want it to be a bit structured you CAN use the Apache2 built in VHosts System in /etc/apache/sites-availible/ with multiple files for every site (VHost).
If you want you could use nano /etc/apache2/sites-availible/mypage1 and then activate or deactivete it via the a2ensite command. Like a2ensite mypage1.

Multiple Apache Location directives for same path

I have a web application currently being served on two HTTPS ports - let's say 443 and 8443. The application has an Apache HTTP server as the front end and I am running into trouble setting up Apache config to exclude certain paths on one of the ports. I have my config set up as below in Apache
<Location /MyApp>
AuthType SOME_AUTH_MODULE
require user valid-user
</Location>
<Location ~ "/MyApp/(Login.html|Welcome.html)">
Satisfy Any
Allow from all
AuthType None
Require all granted
</Location>
I have my virtual hosts setup in Apache as below
<VirtualHost _default_:443>
DocumentRoot /path/to/my/files
Servername www.example.com:443
Other details go here
</VirtualHost>
<VirtualHost _default_:8443>
DocumentRoot /path/to/my/files
Servername www.example.com:8443
Other details go here
</VirtualHost>
What are the expected problems with above configuration, considering that Location directive doesn't take host and port information? Does Location directive use the first matching entry OR will it use one of after the other?
More details for folks who know Shibboleth
The first Location entry allows users to access the application in an SSO (Single Sign On) environment. The second entry is designed to allow users to access the same virtual host on a different port (8443) without going through SSO. What we are seeing is, the request headers are lost towards the end of the processing chain. When I remove the second Location entry all works fine.
Put the /Location directive inside the vhost directive you want to secure.
<VirtualHost _default_:443>
DocumentRoot /path/to/my/files
Servername www.example.com:443
<Location /MyApp>
AuthType SOME_AUTH_MODULE
require user valid-user
</Location>
Other details go here
</VirtualHost>
<VirtualHost _default_:8443>
DocumentRoot /path/to/my/files
Servername www.example.com:8443
Other details go here
</VirtualHost>

Apache2 host two sites on the same server

I am trying to host subversion and wiki on the same site.
I have created two files in /etc/apache2/sites-available
in "subversion"
I have
<VirtualHost -myserverIP-:80>
ServerAdmin webmaster#localhost
ServerName svn.example.com
DocumentRoot /var/svn/repos
<Location /svn/repos>
DAV svn
SVNPath /var/svn/repos
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/passwords
Require valid-user
</Location>
</VirtualHost>
and in "wiki" I have
<VirtualHost -myserverIP-:80>
ServerAdmin webmaster#localhost
ServerName wiki
ServerAlias -myserverIP-
DocumentRoot /home/www/wiki/html
<Directory /home/www/wiki/html>
AllowOverride None
Options -Indexes -MultiViews -SymLinksIfOwnerMatch +FollowSymLinks
Order allow,deny
allow from all
</Directory>
<Location /wiki>
</Location>
<DirectoryMatch "^/home/www/wiki/html/(data|conf|bin|inc)/">
Order allow,deny
Deny from all
Satisfy All
</DirectoryMatch>
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
ErrorLog /home/www/wiki/logs/error.log
CustomLog /home/www/wiki/logs/access.log combined
</VirtualHost>
However now, when I browse to the IP address of the server, I get the contents of the /var/svn/repos directory, wheras when I just had the wiki page, I got the wiki index page. I can actually go to -IPaddress-/svn/repos and see the SVN repository, but -IPaddress-/wiki does not work.
Thanks for the tips
Both your virtual hosts are on port 80 on the same machine. Apache can only guess which one you want to use. It is guessing the subversion one and browsing to the DocumentRoot specified.
You need to differentiate the virtual hosts, or browse to the server using the server name rather than IP.
Instead you could setup the SVN location inside your other virtual host.
Also consider using /etc/apache2/mods-available/dav_svn.conf depending on your Operating System.
However now, when I browse to the IP address of the server, I get the contents of the /var/svn/repos directory, wheras when I just had the wiki page, I got the wiki index page. I can actually go to -IPaddress-/svn/repos and see the SVN repository, but -IPaddress-/wiki does not work.
When you make a request to apache and the hostname you are using isn't defined by any ServerName or ServerAlias in any of the vhosts, apache returns the default vhost, which is always the first vhost in the file (or in the file with the name that's the smallest lexiconical order, e.g. 00-default_vhosts.conf). In your case, your SVN vhost is first so it is the "default" vhost. If you swap the 2 around the other one would be the "default" vhost.

example.com VirtualHost on local machine

What I am trying to do : To add a site (example.com) to apache2/sites-available (I have specified its document root) and then enable it and after that access it on my local machine (as example.com in browser). I have some following queries :
Is it possible to create a website and give a specific domain (example.com) to it?
What are the steps I need to follow in order to create a site, give a domain and access it on my local machine ONLY?
NOTE: I have the content of site. I want to create a new site and I do not want to change the default site(i.e. apache2/sites-available/default) of Apache.
UPDATE:
I faced a error while restarting Apache (I have added a VirtualHost as described)
ERROR
CustomLog takes two or three arguments, a file name, a custom log format string or format name, and an optional "env=" clause (see docs)
Action 'configtest' failed.
The Apache error log may have more information.
...fail!
My site's file
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName dev.subhransu.com
ScriptAlias /private /home/hg/repositories/private/hgweb.cgi
<Directory /home/hg/repositories/private/>
Options ExecCGI FollowSymlinks
AddHandler cgi-script .cgi
DirectoryIndex hgweb.cgi
AuthType Basic
AuthName "Mercurial repositories"
AuthUserFile /home/hg/tools/hgusers
Require valid-user
</Directory>
ErrorLog ${APACHE_LOG_DIR}/dev.subhransu.com_error.log
# Possible values include: debug, info, notice, warn, error, cr$
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/dev.subhransu.com_ssl_access.lo$
SSLEngine on
SSLCertificateFile "/etc/apache2/ssl/dev.subhransu.com.crt"
SSLCertificateKeyFile "/etc/apache2/ssl/dev.subhransu.com.k$
</VirtualHost>
httpd.conf file
<VirtualHost *:80>
ServerName dev.subhransu.com
ServerAlias www.dev.subhransu.com
</VirtualHost>
I think the feature you may be looking for is vhosts. With vhosts you can create any number of sites, each setup independently of the other. For each vhost you can specify the 'ServerName' directive which is your domain, which can be anything you want it to be. And then in your computers hosts file you can route all your calls for that domain to localhost.
If you only have one site that you need to setup, just edit the default apache configuration, leaving vhosts alone, and then update the hosts file on your machine as I mentioned earlier.
References:
vhost examples
How to edit your hosts file
In httpd.conf (or vhosts), the ServerName and ServerAlias settings are what domain names Apache will respond to
ServerName example.com
ServerAlias www.example.com
then just edit your hosts file to point example.com to 127.0.0.1