Multiple domains on apache server - apache

First a quick disclaimer, I'm not a 'server guy' or a 'unix pro' or anything like that, I'm a web programmer who got stuck doing server works since I ran linux (ubuntu) on my netbook.
I'm trying to set up an apache server running on Debian to automagically serve multiple domains, each domain needs to have its own directory in /var/www.
Since this is the last thing I do for this company I really need it to be easy for my successor (who is even more a beginner at servers than I am), to create more domains without having to muck around with ssh or /etc/apache2/sites-available, so what I'm looking for is basically any magic mumbo-jumbo in default (or apt-get, or conf.d) that makes the server start serving any domain that has a matching folder in /var/www they will ofcourse have to initiate domain transfers the usual way.
I have no problem setting up domains individually.
Ick... hope the above makes sense to someone.

To serve multiple domains from Apache, you'll need Apache Virtual Hosts. You can start serving any domain that has a matching folder in /var/www" with Apache Virtual Hosts using mod_vhost_alias.
The following configuration will take the fully-qualified domain name (like www.example.org) and use it as the variable '%0'. So, to serve out 'www.example.org', you create a directory at /var/www/www.example.org/docs , and place your HTML content there. Your Cgi script will go in /var/www/www.example.org/cgi-bin/
<VirtualHost 192.168.1.100:80>
# get the server name from the Host: header
UseCanonicalName Off
VirtualDocumentRoot /var/www/%0/docs
VirtualScriptAlias /var/www/%0/cgi-bin
</VirtualHost>
Then, point 'www.example.org' to '192.168.1.100', and Apache will happily serve that Virtual Host.

Untested Code with flavor of Ubuntu
sudo a2enmod rewrite
vi /etc/apache/sites-enabled/000-default
NameVirtualHost *
<VirtualHost *>
DocumentRoot /var/www/
RewriteEngine On
RewriteRule ^(.*)$ %{HTTP_HOST}/$1
</VirtualHost>
sudo /etc/inid.d/apache2 restart

Related

How to configure phabricator with a bare domain url?

I'm trying to run phabricator on my home server. The last thing I struggle with is to use phabricator with a bare url. I've set up a virtual host (apache 2.4) using a seperate port for phabricator and added the required rewrite rules:
<VirtualHost *:81>
DocumentRoot /var/www/html/phabricator/phabricator/webroot
RewriteEngine on
RewriteRule ^(.*)$ /index.php?__path__=$1 [B,L,QSA]
<Directory "/var/www/html/phabricator/phabricator/webroot">
Require all granted
</Directory>
</VirtualHost>
Unfortunately, phabricator demands a non-root url. Any ideas?
I get the following error message:
User moodboom found a solution but did not post the answer at how-to-configure-phabricator-with-a-non-root-url.
It doesn't look like it demands a non-root URL from the post you pointed to. It looks like the reverse, it demands a root URL. As quoted in the answer you mentioned:
You can either install Phabricator on a subdomain (like
phabricator.example.com) or an entire domain, but you can not install
it in some subdirectory of an existing website.
Since there wasn't any easy way to solve this, I hat to set up a local DNS server (dnsmasq) to get rid of this problem. Manually changing the host file on every single client is possible but too tedious and error prone. Dnsmasq on the other hand was easy to setup on ubuntu 16.04 and will keep my local network a bit more organized.
Cheers,
O.Schmitz

Apache webserver rewrite all URL's excluding some

I'm using apache httpd v2.2 server as a frontend proxy for our actual tomcat web server which hosts the Java web application.
I want to forward all urls received by apache webserver other than those having the prefix /product to tomcat.
I've tried the following set up in httpd.conf but it' doesn't seem to work
<VirtualHost *:6111>
ServerName localhost
RewriteEngine on
RewriteRule !^(/product($|/)) http://localhost:1234/$1
Alias /product /opt/productdoc
</VirtualHost>
I tried to follow Redirect site with .htaccess but exclude one folder but was not successful
Basically all http://localhost:6111/product urls should serve from hard drive (using alias)
Any other url should be forwarded to http://localhost:1234/<original-path>
You probably want to use something like mod_jk http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html.
There are a ton of examples and tutorials and it should be pretty simple to setup and install. Now that you know the name of the connection technology, you should probably be able to find more information.
Using modjk also allows you to secure your tomcat server and keep the public off of it.

Define local site in Apache - Use port other than 80

I'm wondering if anyone can help me define a new local VirtualHost using Apache.
The goal is to have a site that is viewable only from the local network (hidden behind a firewall). Right now I have Webmin installed and it runs on transaction:10000. I am trying to get the other site running on transaction:7000.
The following does not work:
DocumentRoot /var/path
Is there a better way to do this? I'm new to Apache and trying to figure this out.
Summary: Need local /var/path directory to run on a port other than 80 for local access only.
I'm assuming that you don't know to Apache Virtual Host Code. I will show you how to use it. If this didn't help you please don't hesitate to reply to me.
You must place code in your HTTPD.CONF which can be found in the conf folder. If your file is called wwwroot instead just change the name in the code below BUT DO NOT CHANGE THE NAME OF THE FOLDER!!!
NameVirtualHost 111.22.33.44
<VirtualHost *:7000>
ServerName www.domain.tld
ServerPath /domain
DocumentRoot /htdocs/domain
</VirtualHost>
What does this mean? It means that a request for any URI beginning with "/domain" will be served from the virtual host www.domain.tld. This means that the pages can be accessed as domain.tld/domain/ for all clients, although clients sending a Host: header can also access it as domain.tld/.
In order to make this work, put a link on your primary virtual host's page to http://www.domain.tld/domain/. Then, in the virtual host's pages, be sure to use either purely relative links (e.g., "file.html" or "../icons/image.gif") or links containing the prefacing /domain/ (e.g., "http://www.domain.tld/domain/misc/file.html" or "/domain/misc/file.html").
So all domains will be pointed to your IP address and based on the domain name if it is "www.domain.tld" it will take you to the folder "/htdocs/domain" or "/wwwroot/domain"
EDIT:
<Directory "/var/path/">
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
This lets access to the "/var/path/" folder from only localhost which is where Apache is configured which is on your computer!
Good Luck!!!

404 with VirtualHost and Subdirectories with Apache (httpd)

Note: apparently there's a collision on the ServerName in my virtualhost entries and I need to make some changes to my /etc/hosts files. Looking into this but any insight is appreciated. Thanks
=======================================
(note I replaced http:// with hxxp:// to allow stackoverflow to let me post this)
I have a server, 10.1.1.1 that I am going to host multiple WordPress installations on in subdirectories. Specs on the server:
OS: RHEL 6.2 Santiago
Apache version: Apache/2.2.15 (Unix)
PHP version: 5.3.9
MySQL version 5.5.20
The first WordPress Installation I want to run from the virtual directory site_one (i.e. hxxp://10.1.1.1/site_one) -- the code for this site is to reside in /var/www/sites/site_one
The second WordPress Installation I want to run from the virtual directory site_two (i.e. hxxp://10.1.1.1/site_two) -- the code for this site is to reside in /var/www/sites/site_two
I have also dropped a dummy hello world index.html file in /var/www/sites
--
I have made the following changes to my httpd.conf:
DocumentRoot for the entire site is set to /var/www/sites i.e.:
DocumentRoot "/var/www/sites"
at the very bottom of httpd.conf I have the following VirtualHost directives (I replaced < and > with [ ] because I couldn't get stack overflow to output < blocks >:
NameVirtualHost *:80
[VirtualHost *:80]
ServerName 10.1.1.1
DocumentRoot /var/www/sites/site_one
Alias /site_one /var/www/sites/site_one/
[/VirtualHost]
[VirtualHost *:80]
ServerName 10.1.1.1
DocumentRoot /var/www/sites/site_two
Alias /site_two /var/www/sites/site_two/
[/VirtualHost]
I check the syntax of httpd (httpd -t) and the sytax is OK
I restart httpd
--
If I try to access hxxp://10.1.1.1/site_two it gives me a 404 and the error_log reports that it is looking in /var/www/sites/sites_one/site_two/ for the file... Obviously I want it to not look there but in /var/www/sites/site_two/ ... what am I doing wrong? Thanks for any and all help!
See the Apache documentation. http://httpd.apache.org/docs/2.2/vhosts/name-based.html
You are trying to use Name Based Virtual Host because you only have one IP address. This is fine but you are missing the DNS part of how this works. From the documentation: "you need only configure your DNS server to map each hostname to the correct IP address and then configure the Apache HTTP Server to recognize the different hostnames."
The first listed virtual host is always the default host. That is why your site_one will behave the way you "think" it is supposed to, however when you try to access site_two, it falls under the default virtual host.
You have the wrong idea about how Virtual Hosts work. What you are trying to do can be accomplished using aliases, however if anywhere in your code you refer to document root, you have to follow it up with which site you are referring to.
E.g. in PHP code something like this:
require($_SERVER['DOCUMENT_ROOT']."/site_one/directory/to/wherever

MAMP, Apache, Wordpress and the case of the mysterious port number

I'm developing a few sites with Wordpress on a local server. I have my MAMP (2.0.1) running with the default port numbers for Apache and MySQL on Lion (10.7.2). It's been working quite well until I recently encountered a perplexing problem.
One site in particular has undergone a few internal domain/vhost changes (this is how I came to the conclusion of using the default port numbers re:my own Wordpress development) which are referenced in my /etc/hosts file and also in my MAMP apache httpd.conf VirtualHosts section. Now when I visit this particular development domain defined in the hosts and httpd.conf vhost, it gives me a browser error stating that it couldn't establish a connection to dev.example.com:8888 (the Wordpress index.php and htaccess files are in the folder index). I'm a bit annoyed and confused as I've changed the MAMP ports to the default, yet this references the 8888 default MAMP apache port only on the domain index and doesn't want to sway its course even if I visit dev.example.com:80. I can access files and folders within the domain by specifically typing them in, but visiting the domain index as it is gives me this error with the default port number. I have no idea why that is and haven't been able to find a solution via the internet.
Some search results have mentioned incorrect line formats in the hosts and httpd.conf files, but mine are all Unix LF based so that solution hasn't made a difference. I've removed Wordpress from the domain's folder structure and tried again but it still gives me the same error. On another domain I'm using with Wordpress it works fine; the folders are set up exactly the same way, as are the entries in the hosts and the httpd.conf files. I get no apache errors when I visit the particular erroring domain as well. I'm just a bit stumped on the whole thing.
Hosts entry:
127.0.0.1 dev.example.com
Vhost entry:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName dev.example.com
DocumentRoot "/Sites/example.com"
</VirtualHost>
Wordpress config:
sql.wp_options.siteurl = http://dev.example.com/wp
sql.wp_options.home = http://dev.example.com/