I'm currently using name-based virtual host configuration, to server about 5 different websites from the same IP address, just like in the apache documentation:
<VirtualHost *:80>
ServerName www.domain.tld
DocumentRoot /www/domain
</VirtualHost>
<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>
Is it possbile to have something like:
<VirtualHost *:80>
ServerName www.domain.tld/folderpath
DocumentRoot /www/software
</VirtualHost>
The webpages in this folder are using a different software stack, and I'd like to keep it nicely separate. I tried the method above but it didn't work.
It's not possible the way you show - a VirtualHost is always just a host. But you could use an Alias.
<VirtualHost *:80>
ServerName www.domain.tld
DocumentRoot /www/domain
Alias /folderpath /www/software
</VirtualHost>
Is it possible to have a different vhost for each application like that:
<VirtualHost *:80>
ServerName www.domain.tld
DocumentRoot /www/domain
</VirtualHost>
<VirtualHost *:80>
ServerName www.domain.tld
Alias otherApp /www/otherApp
</VirtualHost>
I add to the alias.conf file (on a windows machine).
Remember that if it outside the 'document root' path, you'll need permissions
<IfModule alias_module>
#### FolderPath ####
Alias /folderpath "E:/any/path/you/like"
<Directory "E:/any/path/you/like">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
#### Another ####
Alias /another "E:/another/different/path"
<Directory "E:/another/different/path">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</IfModule>
Related
I'm trying to configure my apache vhosts file to have a localhost/something hostname and "alias" hostnames. I'm working with google api's currenctly and they are not accepting custom aliases as url's, so I can't make it work with my custom url's. Any thoughts of what to do? My current config that's not working:
<VirtualHost 127.0.0.1:80>
ServerName localhost/go
ServerAlias localhost/go
DocumentRoot "D:/username/Web/server.dev/go"
</VirtualHost>
<Directory "D:/username/Web/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
</Directory>
<VirtualHost *:80>
ServerName api.server.dev
ServerAlias api.server.dev
DocumentRoot "D:/username/Web/server.dev/api"
</VirtualHost>
##... more custom urls with subdomains cut out because it's unnecessary
<VirtualHost *:80>
ServerName adstrck.server.dev
DocumentRoot "D:/username/Web/server.dev/adstrck"
</VirtualHost>
### ALL OTHERS ###
<VirtualHost *:80>
ServerName www.server.dev
ServerAlias server.dev *.server.dev
DocumentRoot D:/username/Web/server.dev
</VirtualHost>
When I'm trying to access 127.0.0.1/go or localhost/go I get an internal server error.
Maybe what you want is something like this
<VirtualHost 127.0.0.1:80>
ServerName localhost
ServerAlias server.dev *.server.dev
DocumentRoot "D:/username/Web/server.dev"
</VirtualHost>
<Directory "D:/username/Web/server.dev">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
</Directory>
Then use a url like http://localhost/go to view the site.
Depending on your OS/browser, you may be able to add a development subdomain to localhost. E.g.
<VirtualHost *:80>
ServerName dev1.localhost
## rest of your config
## e.g. ServerAlias my.website.on.the.internet.com
DocumentRoot /var/www/dev1
</VirtualHost>
<VirtualHost *:80>
ServerName dev2.localhost
DocumentRoot /var/www/dev2
</VirtualHost>
# Default / catch-all
<VirtualHost *:80>
DocumentRoot /var/www/html
</VirtualHost>
I then pointed my browser to dev1.localhost and that resolved to dev1 and likewise for dev2.localhost and localhost by itself resolved to the default apache page.
This resolved my similar problem. Tested on Apache in a Debian WSL. Worked on Windows Chrome, failed on Windows Firefox. Based on this SO: https://stackoverflow.com/a/35124491
I want any domain to point a CNAME on my vhosts for that i use
ServerAlias *
in my vhosts but it only works with one vhost if I add it in both the CNAME pointed to the second vhost serves the contented from the first vhost.
e.g:
1st: files.domain.com CNAME to files.example.com
2nd: r.domain.com CNAME to r.example.com
but second one is also serving files.example.com
My httpd.conf has these two vhosts
<VirtualHost *:80>
ServerAdmin admin#example.com
DocumentRoot /var/www/files.example.com
ServerName files.example.com
ErrorLog /var/www/files.example.com/logs/error_log
CustomLog /var/www/files.example.com/logs/custom_log common
<Directory "/var/www/files.example.com">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin#example.com
DocumentRoot /var/www/r.example.com
ServerName r.example.com
ErrorLog /var/www/r.example.com/logs/error_log
CustomLog /var/www/r.example.com/logs/custom_log common
<Directory "/var/www/r.example.com">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
This may not be directly related but it could be of help to others: you can actually put many aliases in the same virtual host entry (in my case for the same domain):
ServerName example.com
ServerAlias mail.example.com files.example.com r.example.com
And be sure to include all these as server-aliases also while creating an SSL Certificate for the domain.
You have to add ServerAlias lines
below ServerName files.example.com add ServerAlias files.domain.com
and below ServerName r.example.com add ServerAlias r.domain.com
In your case apache uses files.example.com as default vhost, because it is first one.
I solved this problem by setting a dedicated ip on the vhost where I want the ServerAlias to be * and it worked
<VirtualHost 192.168.1.55:80>
ServerAdmin admin#example.com
DocumentRoot /var/www/r.example.com
ServerName r.example.com
ServerAlias *
ErrorLog /var/www/r.example.com/logs/error_log
CustomLog /var/www/r.example.com/logs/custom_log common
<Directory "/var/www/r.example.com">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
If I go for http://example.com then its pointing to /var/www/html
Now I am in need that if I go for http://example.com/dashboard then it will point to /var/www/example/public. Or If this not possible then /var/www/html/example/public would also be okay.
And again I need that if I go for http://wildcardsubdomain.example.com/ then also it will point to /var/www/example/public. Or If this not possible then /var/www/html/example/public would also be okay.
How can I make so?
I have tried with this but /dashboard not working:
ServerName example.com
# Listen for virtual host requests on all IP addresses
UseCanonicalName Off
#dynamic subdomain provisioning
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *:80>
#WORKING
ServerName user.example.com
ServerAlias *.example.com
DocumentRoot /var/www/example/public
</VirtualHost>
<VirtualHost *:80>
#NOT WORKING
ServerName www.example.com/dashboard
ServerAlias *.example.com/dashboard
DocumentRoot /var/www/example/public
</VirtualHost>
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
For dashboard I could solve that using the Alias Directive
<VirtualHost *:80>
DocumentRoot /var/www/html
Alias /dashboard /var/www/example/public
<Directory /var/www/example/public>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I need to install a server with Apache 2.2 on Linux and I need to do two VirtualHosts differentiated by URI.
But with only one domain name and one ip address. And I can't use Alias.
I tried something like that but that doesn't work :
<VirtualHost *:80>
DocumentRoot /var/www/app1
ServerName localhost/app1
ServerAlias www.localhost/app1
<Directory /var/www/app1>
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/app2
ServerName localhost/app2
ServerAlias www.localhost/app2
<Directory /var/www/app2>
Allow from all
</Directory>
</VirtualHost>
Thank you to the first answer here, it's working : https://serverfault.com/questions/588841/two-apps-on-apache-server-with-uri
I put the answer here if one day the link doesn't work :
What you could do is set up a reverse proxy to different virtual hosts listening only on loopback.
You would get in your www.localhost virtualhost:
<VirtualHost *:80>
DocumentRoot /var/www/
ServerName localhost
ServerAlias www.localhost
ProxyPassReverse /app1/ http://webapp1.local/
ProxyPassReverse /app2/ http://webapp2.local/
</Virtualhost>
And create two virtualhosts for the apps:
<VirtualHost 127.0.0.1:80>
DocumentRoot /var/www/app1
ServerName webapp1.local
<Directory /var/www/app1>
Allow from all
</Directory>
</Virtualhost>
<VirtualHost 127.0.0.1:80>
DocumentRoot /var/www/app2
ServerName webapp2.local
<Directory /var/www/app2>
Allow from all
</Directory>
</Virtualhost>
Make sure to add webapp1.local and webapp2.local to your /etc/hosts file.
Since you have only a single domain name and only a single ip address available there is no means for the apache server to distinguish which host is meant. Therefore there is noo sense in defining VirtualHosts here.
However you certainly can place two apps in separate folders inside your DocumentRoot:
ServerName whatever-your-domain.is
DocumentRoot /var/www
<Directory /var/www/app1>
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/app2>
Order allow,deny
Allow from all
</Directory>
Then you'd call those apps by their paths:
apps1: http://whatever-your-domain.is/app1
apps2: http://whatever-your-domain.is/app2
Don't forget to take care of requests to the "main folder" of that single host: /var/www which can be reached by http://whatever-your-domain.is/
I have two applications running in the same server and I would like to have one served from subpath in the url (i.e):
foo.com -> /var/www/foo
foo.com/bar -> /var/www/bar
I'm trying to do an alias but is not working:
<VirtualHost *:80>
ServerAdmin webmaster#foo.com
ServerName foo.com
DocumentRoot /webapps/foo/current/public
<Directory /webapps/foo/current/public>
AllowOverride all
Options -MultiViews
</Directory>
RailsEnv staging
Alias /blog /webapps/blog/current
<Directory /webapps/blog/current>
allow from all
Options +Indexes
</Directory>
Do you know why this is not working?
I also tried serverpath directive without any success.
Do you know how to achieve this?
Thanks in advance.
Use AliasMatch instead of Alias:
AliasMatch ^/bar/?(.*) /var/www/bar/$1
Or, in your case:
AliasMatch ^/blog/?(.*) /webapps/blog/current/$1
Have you considered using another separate subdomain, like bar.foo.com for your other application?
Here's how you'd set that up:
<VirtualHost *:80>
ServerAdmin webmaster#foo.com
DocumentRoot /var/www/foo
ServerName foo.com
ServerAlias foo.com www.foo.com
ErrorLog logs/foo.com_Error_Log
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#foo.com
DocumentRoot /var/www/bar
ServerName bar.foo.com
ErrorLog logs/bar.foo.com_Error_Log
</VirtualHost>