apache2 configuring two domains in same server - dns

I am trying to configure two domains in one server. My environment is
My domain 1 is : www.streetview.live
My domain 2 is : www.riverview.live
Ubuntu 20.04
PHP 7
apache2
In my /etc/apache2/sites-enabled/000-default.conf I have the created the links for both the domains one after the other.
First for www.streetview.live
<VirtualHost *:80>
ServerName www.streetview.live
ServerAlias streetview.live
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/streetview
<Directory /var/www/html/streetview>
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>
<VirtualHost *:443>
ServerName www.streetview.live
ServerAlias streetview.live
DocumentRoot /var/www/html/streetview
SSLEngine on
SSLCertificateFile /etc/ssl/certs/streetview/www_streetview_live.crt
SSLCertificateKeyFile /etc/ssl/certs/streetview/www_streetview_live.key
SSLCertificateChainFile /etc/ssl/certs/streetview/www_streetview_live.ca-bundle
</VirtualHost>
Followed by www.riverview.live
<VirtualHost *:80>
ServerName www.riverview.live
ServerAlias riverview.live
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/riverview
<Directory /var/www/html/riverview>
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>
<VirtualHost *:443>
ServerName www.riverview.live
ServerAlias riverview.live
DocumentRoot /var/www/html/riverview
SSLEngine on
SSLCertificateFile /etc/ssl/certs/riverview/www_riverview_live.crt
SSLCertificateKeyFile /etc/ssl/certs/riverview/www_riverview_live.key
SSLCertificateChainFile /etc/ssl/certs/riverview/www_riverview_live.ca-bundle
</VirtualHost>
I have loaded all the files in the path /var/www/html/. I have one folder for streetview.live and another for riverview.live as follows
/var/www/html/streetview/
/var/www/html/riverview/
In the DNS server I have mapped the IP to www.streetview.live and similarly for the other site.
However, When I load the page, I face two problems.
The respective sites open only when I use www.streetview.live/streetview on the browser and similarly for riverview.live, I have to use www.riverview.live/riverview`.
For both the https is not getting enabled.
The server is hosted in AWS and I do have the ports opened in Security Group.

Related

How can I serve multiple websites from specific paths on Apache?

I have two projects - site_a and site_b - that I would like to host on an Ubuntu server running Apache. I want these two projects to be accessed at paths {domain}/site_a and {domain}/site_b, respectively; I am not interested in having separate domains for them.
With the exception of each project's public/ directory, each project contains files that I do not want to be publicly accessible. So, I have stored the projects in /home instead of in /var/www.
I have tried specifying ServerName in both projects' .conf files and <Directory> in apache2.conf, but am unsure on how to make this work. At the moment, whenever I access {domain}/ in a browser, I get shown the contents of site_a/public.
Here is what I tried so far:
site_a.conf:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName localhost/site_a
DocumentRoot /home/site_a/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
site_b.conf:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName localhost/site_b
DocumentRoot /home/site_b/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
apache2.conf:
<Directory /home/site_a>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /home/site_b>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Since you want both sites to respond on the same domain, you can only have 1 VirtualHost. Apache has no way to know what is site A and site B based on the domain if you only have 1.
One domain, 2 sites
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin admin#example.com
documentRoot "YOUR_DIRECTORY_PATH/apache/htdocs"
DirectoryIndex index.html
ErrorLog "logs/80_error_log"
CustomLog "logs/80_access_log" combined
</VirtualHost>
Setup your files like this:
under YOUR_DIRECTORY_PATH/apache/htdocs
mkdir site_a: put your files for site a here
mkdir site_b: put your files for site b here
One domain, 2 ports
<VirtualHost *:80>
SITE A CONFIG
</VirtualHost>
<VirtulaHost *:81>
SITE B CONFIG
</VirtualHost>
To see site a: http://example.com/
To see site b: http://example.com:81/

Httpd VHost not using correct DocumentRoot

I am having trouble getting a virtual host file to work correctly.
Here is my virtualhost file
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
DocumentRoot "/var/www/example.com/public_html"
SSLEngine on
SSLCertificateFile /etc/ssl/example.com.crt
SSLCertificateKeyFile /etc/ssl/example.com.key
# SSLCertificateChainFile /etc/ssl/origin_ca_rsa_root.crt
</VirtualHost>
<Directory "/var/ww/example.com/public_html">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
The issue is that when accessing the domain is pulling from the default path of /var/www/html instead of the documentroot specified in the conf file.
Within the httpd.conf file I have the IncludeOptional /sites-enabled/example.com.conf and it works correctly, including SSL however the DocumentRoot is not being pulled correctly.
Here is my httpd.conf file: https://pastebin.com/2cuqDwPY
System OS: AlmaLinux8

Hosting multiple subdomains on a different Apache server

We host our website on a Microsoft server. For reasons I'm not going to explain here, we decided to host 3 subdomains on an Ubuntu 16.04 server.
My question is how to configure the virtual hosts on Apache for this.
I have (I think) all the info I need here.
My doubt is: As ServerName I'm going to write the subdomain (see example below), right? Basically, I'm going to treat the subdomains as if I had 3 different websites.
/etc/apache2/sites-available/sudomain1.example.com.conf
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName sudomain1.example.com
DocumentRoot /var/www/sudomain1.example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
/etc/apache2/sites-available/sudomain2.example.com.conf
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName sudomain2.example.com
DocumentRoot /var/www/sudomain2.example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
/etc/apache2/sites-available/sudomain3.example.com.conf
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName sudomain3.example.com
DocumentRoot /var/www/sudomain3.example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Apache virtualhost configuration

I am tring to set two virtual host (example.com.conf and test.com.conf):
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
and
<VirtualHost *:80>
ServerAdmin admin#test.com
ServerName test.com
ServerAlias www.test.com
DocumentRoot /var/www/test.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
The problem is that if I go on localhost in my browser it is shown the website www.example.com. If I type localhost/test.com there is error not found. My goal should be to address both website with localhost/example.com and localhost/test.com.
Sounds like you could use the ServerPath directive for apache, in your case something like this should work:
<VirtualHost 127.0.0.1>
# primary vhost
DocumentRoot "/var/www/example.com"
RewriteEngine On
RewriteRule "." "/var/www/example.com/public_html"
# ...
</VirtualHost>
<VirtualHost 127.0.0.1>
DocumentRoot "/var/www/example.com/public_html"
ServerName localhost
ServerPath "/example/"
RewriteEngine On
RewriteRule "^(/sub1/.*)" "/var/www/example$1"
# ...
</VirtualHost>
<VirtualHost 127.0.0.1>
DocumentRoot "/var/www/test.com/public_html"
ServerName localhost
ServerPath "/test/"
RewriteEngine On
RewriteRule "^(/sub2/.*)" "/var/www/test$1"
# ...
</VirtualHost>
The first Vhost would be so that localhost defaults to example.com page.
if you want to browse to these folders under any virtual host, like http://localhost/test.com, then you simply need an alias directive inside a location tag appended to the end of any active virtual host
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster#localhost
DocumentRoot /var/www
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<Location "/example.com">
Alias "/var/www/example.com/public_html"
</Location>
<Location "/test.com">
Alias "/var/www/test.com/public_html"
</Location>
Or you can put it inside the virtual host if you don't want it available anywhere else
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster#localhost
DocumentRoot /var/www
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Location "/example.com">
Alias "/var/www/example.com/public_html"
</Location>
<Location "/test.com">
Alias "/var/www/test.com/public_html"
</Location>
</VirtualHost>

htaccess with virtualhost not working

I have a local dev Debx64 machine with a number of virtualhosts configured.
the primary URL is set as
<VirtualHost *:80>
ServerAdmin webmaster#blah.com
ServerName blah.com
ServerAlias blah.com
DocumentRoot /home/blah/v1.blah.com
<Directory /home/blah/v1.blah.com/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
AccessFileName .htaccess
ErrorLog /home/blah/blah_logs/v1.blah.com.in-error_log
CustomLog /home/blah/blah_logs/v1.blah.com.in-access_log common
</VirtualHost>
and that redirects to the primary operating VH
<VirtualHost *:80>
ServerAdmin webmaster#blah.com
ServerName v1.blah.com
ServerAlias v1.blah.com
DocumentRoot /home/blah/v1.blah.com
<Directory /home/blah/v1.blah.com/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
AccessFileName .htaccess
ErrorLog /home/blah/blah_logs/v1.blah.com.in-error_log
CustomLog /home/blah/blah_logs/v1.blah.com.in-access_log common
</VirtualHost>
I have a .htaccess set up on v1.blah.com to parse .html as .php
Options +ExecCGI
AddHandler php-fcgi .php .html
Action php-cgi /home/php5-fcgi
<FilesMatch "^php5?\.(ini|cgi)$">
Order Deny,Allow
Deny from All
Allow from env=REDIRECT_STATUS
</FilesMatch>
This works fine if I access the URL as v1.blah.com, however if I access it as blah.com the .htaccess is not invoked and the .html is served as normal.
What Am I missing? is there something in php.ini that needs to be changed?
Is there a particular reason why you need to have two separate entries for your hosts? Seeing as they both use the same Log Files, and DocumentRoot, could you not add blah.com to the list of ServerAlias' ?
So you would end up with the following configuration below:
<VirtualHost *:80>
ServerAdmin webmaster#blah.com
ServerName v1.blah.com
ServerAlias v1.blah.com blah.com
DocumentRoot /home/blah/v1.blah.com
<Directory /home/blah/v1.blah.com/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
AccessFileName .htaccess
ErrorLog /home/blah/blah_logs/v1.blah.com.in-error_log
CustomLog /home/blah/blah_logs/v1.blah.com.in-access_log common
</VirtualHost>

Resources