apache2 virtual host sub domain migration - apache2

electronicarchitect.com is the old domain,
i am looking to replace with rrh.com
What i want:
electronicarchitect.com : rrh.com
portal.electronicarchitect.com : portal.rrh.com
currently, when i go to portal.rrh.com, for some reason i takes me to the same location as rrh.com
<VirtualHost *:80>
ServerName electronicarchitect.com
ServerAlias www.electronicarchitect.com
DocumentRoot /var/www/electronicarchitect.com
ErrorLog /etc/apache2/logs/electronicarchitect.com/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
<Directory /var/www/electronicarchitect.com>
AllowOverride All
</Directory>
CustomLog /etc/apache2/logs/electronicarchitect.com/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName portal.electronicarchitect.com
DocumentRoot /var/www/portal.electronicarchitect.com
ErrorLog /etc/apache2/logs/portal.electronicarchitect.com/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
<Directory /var/www/portal.electronicarchitect.com>
AllowOverride All
</Directory>
#alias /php-myadmin/ "/var/www/portal.electronicarchitect.com/php-myadmin/"
#<Directory "/var/www/portal.electronicarchitect.com/php-myadmin">
# AllowOverride All
# Options FollowSymlinks
# Order allow,deny
# Allow from all
# DirectoryIndex index.php
#</Directory>
CustomLog /etc/apache2/logs/portal.electronicarchitect.com/access.log combined
</VirtualHost>
__
<VirtualHost *:80>
ServerName www.rrh.com
ServerAlias rrh.com
ServerAdmin webmaster#rrh.com
DocumentRoot /var/www/electronicarchitect.com/
<Directory /var/www/electronicarchitect.com/>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/electronicarchitect.com.error.log
#Possible Values include: debug, info, notice, warn, error, crit,
#alert, emerg.
LogLevel alert
ServerSignature On
</VirtualHost>
<VirtualHost *:80>
ServerName portal.rrh.com
ServerAdmin webmaster#rrh.com
DocumentRoot /var/www/portal.electronicarchitect.com/
<Directory /var/www/portal.electronicarchitect.com/>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/rrh.error.log
#Possible Values include: debug, info, notice, warn, error, crit,
#alert, emerg.
LogLevel alert
ServerSignature On
</VirtualHost>
sorry for the poor formatting, stackoverflow was giving issues when creating this post.

Have you set up your sub CNAME?
The CNAME record point to subdomain:
portal.electronicarchitect.com (in this case)
Keep in mind DNS can take a while to update/proliferate.
Set up Apache.
Add sub to /etc/apache2/sites-available (you did this already, including for reference for others.)
sub:
<VirtualHost *:80>
ServerName subDomainName.myDomain.com
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://192.168.1.101/
ProxyPassReverse http://192.168.1.101/
</Location>
</VirtualHost>

Related

Why are my two apache2 virtualhosts pointing to the same directory?

I have two virtual hosts setup on my Ubuntu 20.04 Apache2 webserver.
example2.domain.com.conf
DocumentRoot /var/www/Dev
ServerName example2.domain.com
ServerAlias example2.domain.com
<Directory /var/www/Dev/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
example.domain.com.conf
<VirtualHost *:80>
DocumentRoot /var/www/example
ServerName example.domain.com
ServerAlias example.domain.com
<Directory /var/www/example/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Redirect permanent / https://example.domain.com/
</VirtualHost>
and finally: example.domain.com-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
DocumentRoot /var/www/example
ServerName example.domain.com
ServerAlias example.domain.com
<Directory /var/www/example/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /etc/letsencrypt/live/example.domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.domain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
/etc/hosts
127.0.0.1 localhost
127.0.0.1 example2
Ok, so when I go to example2.domain.com it shows the example2 url but displays the files from example.domain.com. example.domain.com works just fine.
What gives?

Ubuntu 12.10 virtualhost conflict

I have two sites on my server. One I access via my IP, x.x.x.x/site1. The other is a registered domain name, www.mysite.com.
Initially, I had only my /etc/apache/sites-available/default file available but when I tried loading either of the sites above I just got my /var/www/index.html output.
I included a new virtualhost for mysite.com with the following code:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/mysite
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/mysite>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Mysite.com only loads when default is disabled but then, x.x.x.x/site1 doesn't.
So, I enable the default virtualhost which has the following code:
<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>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now, x.x.x.x/site1 works but mysite.com does not - instead it loads the /var/www/index.html page.
I'm confused about what the issue is.
In your vhost configuratin for mysite.com you need to add the ServerName directive:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName mysite.com
DocumentRoot /var/www/mysite
[…]

Use bottlepy and php in the same computer

I use ubuntu 12.04 with apache2 and mod_wsgi installed. I want to use bottlepy and php in my local computer.
I know such an issue is already asked by someone else as in Apache mod_wsgi and php in the same domain.
But someone suggest me to make a new question since my problem could be different.
I've change /etc/apache2/sites-available/default into this:
<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>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
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>
<VirtualHost *>
DocumentRoot /home/gofrendi/workspace/kokoropy
ServerName oraiso
WSGIDaemonProcess kokoropy user=www-data group=www-data processes=1 threads=5
WSGIScriptAlias /kokoropy /home/gofrendi/workspace/kokoropy/kokoro.wsgi
<Directory /home/gofrendi/workspace/kokoropy>
WSGIProcessGroup kokoropy
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
The first virtual host is for PHP, and the second one is for bottlepy.
I put my bottlepy application in /home/gofrendi/workspace/kokoropy. And I have kokoro.wsgi in the same directory which contains this script:
import os
sys.path = [os.path.dirname(__file__)] + sys.path
from kokoropy import kokoro_init
PWD = os.path.dirname(os.path.abspath(__file__))
APP_DIRECTORY = 'applications'
APPLICATION_PATH = os.path.join(PWD, APP_DIRECTORY)
application = kokoro_init(application_path = APPLICATION_PATH, run = False)
I've do enable the configuration by using
sudo a2ensite default
sudo service apache2 restart
My PHP scripts are still work as expected. But, whenever I don't know how to access my bottlepy script.
I've also try to remove the PHP part of /etc/apache2/sites-available/default, so that it only consists of
<VirtualHost *>
DocumentRoot /home/gofrendi/workspace/kokoropy
ServerName oraiso
WSGIDaemonProcess kokoropy user=www-data group=www-data processes=1 threads=5
WSGIScriptAlias /kokoropy /home/gofrendi/workspace/kokoropy/kokoro.wsgi
<Directory /home/gofrendi/workspace/kokoropy>
WSGIProcessGroup kokoropy
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
But I still can't get bottlepy work. It just simply show 404 not found.
Do anybody has the same experience? How to make it work?
Thanks.
The problem has been solved.
First I change httpd.conf setting (or in my case /etc/apache2/sites-available/default) nto this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName 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>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
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>
# THIS IS WHERE I START TO EDIT IT:
# It tells apache about wsgi existance
WSGIDaemonProcess kokoropy user=www-data group=www-data processes=1 threads=5
WSGIScriptAlias /kokoropy /home/gofrendi/workspace/kokoropy/kokoro.wsgi
<Directory /home/gofrendi/workspace/kokoropy>
WSGIProcessGroup kokoropy
WSGIApplicationGroup %{GLOBAL}
Options ExecCGI
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
This configuration say that localhost/kokoropy should be handled by the wsgi.
My wsgi script is located at /home/gofrendi/workspace/kokoropy/kokoro.wsgi.
kokoro.wsgi content is as follow:
import os, sys
os.chdir(os.path.dirname(__file__))
sys.path = [os.path.dirname(__file__)] + sys.path
from bottle import default_app
#route('/')
def index():
return 'run with apache'
application = default_app()
If you found internal sever error, when accessing bottlepy, but find no error when accessing php, that is probably some mistake in you wsgi. Just open up the apache log (in my case it is here: /var/log/apache2/error.log)

Why doesn't Apache redirect my IP address to the desired location on my server?

I made a simple page /home/david/mainSite/index.html. I then added a virtual host in Apache to redirect my IP address to this page.
<VirtualHost *:80>
ServerName 74.181.105.228
DocumentRoot /home/david/mainSite
</VirtualHost>
However, when I go to 74.181.105.228after restarting Apache, I get a page with this text instead of "index.html."
Welcome to mydomain.com!
This is the default web page for this server.
The web server software is running but no content has been added, yet.
Why does Apache redirect to the default page instead of "/home/david/mainSite/index.html"?
Here is how my "/etc/apache2/sites-available/default" file looks like.
<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>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
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>
I discovered the answer! It was tricky.
In "apache2.conf", I originally had ServerName 74.181.105.228, which makes accessing 74.181.105.228 via a browser load the default page for my server.
Changing this value in "apache2.conf" to ServerName mydomain.com solves the problem since Apache no longer directs 74.181.105.228 to the default page of my server. In turn, I can direct 74.181.105.228 to load a page from a certain directory in my file system.
My virtual host block still remains
<VirtualHost *:80>
ServerName 74.181.105.228
DocumentRoot /home/david/mainSite
</VirtualHost

subdomains w/o TLD

How do i set up a subdomain w/o a TLD? i have this set under my main config
<VirtualHost *:80>
ServerName bbs.67.777.777.777 #fake bc my server can easily be hacked ATM :(
DocumentRoot /var/www/phpBB
</VirtualHost>
when i goto bbs.serveripaddress i get a Address Not Found error. if i put that above my main config it still doesnt work however the entire site is pointing to /var/www/phpBB instead of /var/www (HUH!?!)
the main v host is
<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
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
RedirectMatch ^/$ /apache2-default/
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
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>
I'm on a debian box using apache2 if that helps.
I don't think that server name (bbs.67.777.777.777 ) will get you anywhere - unless you have it added to your hosts file... Can you ping that address ok?
Why not just make your website the default... if you don't need a default?
You cannot have a subdomain with an IP address. The best way around this is to have a domain or a free subdomain (such as no-ip) to point at your IP address and create a ServerName for that. Remember to add the domain to your server DNS zones.
or make a domain in your host files and use that.

Resources