Apache virtual hosts without domain names, how to set a default site - apache

I've set the following up to serve 2 development sites from the same box without using domain names:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
Alias /projecta /var/www/projecta
Alias /projectb /var/www/projectb
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
This works, but how do I direct requests for just the IP address, that is without a site name postfix, to a 'default' site?

You can use mod_rewrite to redirect to defult site.
RewriteEngine on
RewriteRule ^/$ /projecta [R]

Related

How to register Options Indexes FollowSymLinks AllowOverride All for directory rule in nginx?

the config file in the Apache site has these lines:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/public/
<Directory /var/www/html/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
now I want to add this rule to the Nginx server. I have a shortener URL website that allows customers to use their own custom domain. How do I allow this in the Nginx config file?
Main Domain: www.example.com
If users want to use their own domain they can add unlimited domains that's what I'm trying to achieve with this code. But basically, it's only for the apache and I have installed the script on Nginx server.

Apache Virtual Hosts for Two Sites Not Working Properly

I am trying to have two separate sites with Apache virtual hosts on a test server. I am going to access the sites with the ip address of the instance (for example, http://167.275.122.215). When I enable the following configuration, I would be able to load the first site with just the ip address correctly (with http://167.275.122.215), but not http://167.275.122.215/exp. I get a 404 error when I point to that address. What am I doing wrong here?
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/main
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
Alias /exp /usr/share/wordpress
DocumentRoot /usr/share/wordpress
<Directory /usr/share/wordpress>
Options FollowSymLinks
AllowOverride all
DirectoryIndex index.php
require all granted
</Directory>
</VirtualHost>
In fact, my need is to be able to access the exp (experimental) site through the same ip while the main site is still available (from the original ip address). I tried giving a different port to the experimental site too (like below), but that still gave me a site can't be reached error.
<VirtualHost *:90>
<Directory /usr/share/wordpress>
Options FollowSymLinks
AllowOverride all
DirectoryIndex index.php
require all granted
</Directory>
</VirtualHost>
For port based multiple sites, listing the default port as the second site resolved the issue:
LISTEN 90
<VirtualHost *:90>
DocumentRoot /usr/share/wordpress
<Directory /usr/share/wordpress>
Options FollowSymLinks
AllowOverride all
DirectoryIndex index.php
require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/main
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Subdomain answer to specific folder in Apache

I want to configure an Apache vhost. Practically Basically I want by typing the address files.yyyyyy.ltd answer me the folder destination /var/www/html/alpha/files
This is apache configuration:
<VirtualHost *:80>
DocumentRoot /var/www/html/alpha/files
ServerName files.yyyyyy.ltd
ServerAlias files.yyyyyy.ltd
<Directory /var/www/html/alpha/files >
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
# Other directives here
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
DNS configuration:
yyyyyy.ltd. IN A XXX.XXX.XXX.XXX
www IN CNAME yyyyyy.ltd.
yyyyyy.ltd. IN CNAME files.yyyyyy.ltd.
What is wrong? Do you recommend some other method to achieve the same result?
Thk for help
DNS configuration
you need to change
yyyyyy.ltd. IN CNAME files.yyyyyy.ltd.
to
files IN CNAME yyyyyy.ltd.
you can also set all as A record like
yyyyyy.ltd. IN A XXX.XXX.XXX.XXX
www.yyyyyy.ltd. IN A XXX.XXX.XXX.XXX
files.yyyyyy.ltd. IN A XXX.XXX.XXX.XXX
What i would do to have a faster name resolution.
Apache configuration
Your Apache configuration is correct, but some stuffs are useless:
<VirtualHost *:80>
DocumentRoot /var/www/html/alpha/files
ServerName files.yyyyyy.ltd
<Directory /var/www/html/alpha/files >
Options Indexes FollowSymLinks MultiViews
AllowOverride all
</Directory>
# Other directives here
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
AllowOverride all is there to allow .htaccess, if you don't want .htaccess files, you can remove this command from your configuration.

Add a sudomain for each folder in my userdir path with Apache

I activated the userdir mod with apache2 and configure my domain to get the content of the www folder in my home.
I create a Virtualhost for the main domain which works good.
But now i would like to automatically add a subdomain for each folder in my /home/user/www/
Here is the virtualhost i code, but it redirect all the subdomains to the /home/user/www/
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName mysite.com
ServerAlias *.mysite.com
DocumentRoot /home/user/www/
UseCanonicalName Off
VirtualDocumentRoot /home/user/www/%1
<Directory /home/user/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.mysite.log
LogLevel warn
CustomLog /var/log/apache2.mysite.log combined
</VirtualHost>`
Try changing:
VirtualDocumentRoot /home/user/www/%1
to:
VirtualDocumentRoot /home/user/www/%0
You can read more about this feature at mod_vhost_alias.

Common Rewrite Setting For Multiple VHosts

I am running Apache2 with multiple vhosts in the sites-enabled folder, each looks a bit like this:
<VirtualHost *:80>
ServerName site1.com
ServerAlias www.site1.com
DocumentRoot /home/sites/site1/www/
<Directory /home/sites/site/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
<Directory /home/sites/mainsite/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
# Provide default favicon.ico and robots.txt using rewrite
RewriteOptions Inherit
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteRule ^/(robots\.txt|favicon\.ico)$ /mainsite_alias$0 [PT,NC,L]
</VirtualHost>
The Rewrite code is common to all vhosts (providing a default favicon.ico/robots.txt) but putting this code into httpd.conf does not seem to have any effect - the rewrite logs show nothing.
How can I make this code common to all vhosts without duplicating the code?
Alternatively - is there a better way of achieving default favicons?
Thanks
You could try a AliasMatch:
AliasMatch ^/(robots\.txt|favicon.ico)$ /home/sites/site1/www/mainsite_alias$0
I am using this
<VirtualHost *:80>
ServerAdmin email_at_isp
DocumentRoot "C:/apache/htdocs"
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin_at_server_one.com
DocumentRoot "C:/apache/htdocs/server_one.com"
ServerName server_one.com
ErrorLog "logs/server_one.com-error.log"
CustomLog "logs/server_one.com-access.log" common
</VirtualHost>
and I keep rewrite scripts in .htaccess at the root[C:/apache/htdocs]
I hope it helps somehow, if not enoying. lol