elloo,
i have two virtualhost subdomains point to different directories however when i load both subdomains in the browser, i get them both pointing to same directory. here is my vhost.conf
<VirtualHost *:80>
ServerAdmin admin#domain.com
ServerName subdomain1.domain.com
ServerAlias *.domain.com
#Indexes + Directory Root.
DirectoryIndex index.php
DocumentRoot /subomain1/path/to/directory/trunk
#Logfiles
ErrorLog /subomain1/path/to/directory/trunk/error.log
CustomLog /subomain1/path/to/directory/trunk//access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerAdmin admin#domain.com
ServerName subdomain1.domain.com
ServerAlias *.subdomain.com
DirectoryIndex index.php
DocumentRoot /subomain1/path/to/directory/trunk
SSLEngine On
SSLCertificateFile /ssl/certs/subdomain1.crt
SSLCertificateKeyFile /ssl/private/subdomain1.key
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin#domain.com
ServerName subdomain2.domain.com
ServerAlias *.domain.com
#Indexes + Directory Root.
DirectoryIndex index.php
DocumentRoot /subomain2/path/to/directory/trunk
#Logfiles
ErrorLog /subomain2/path/to/directory/trunk/error.log
CustomLog /subomain2/path/to/directory/trunk//access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerAdmin admin#domain.com
ServerName subdomain2.domain.com
ServerAlias *.subdomain.com
DirectoryIndex index.php
DocumentRoot /subomain2/path/to/directory/trunk
SSLEngine On
SSLCertificateFile /ssl/certs/subdomain2.crt
SSLCertificateKeyFile /ssl/private/subdomain2.key
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
</VirtualHost>
i have tried google however none of the answers seems to help.
i'm using ubuntu server
many thanks in advance
don't know if you ever solved this, but i was having the same problem and it turned out i forgot to change the httpd.conf file like this:
Open the “httpd.conf” and uncomment line #461 (approx) which reads “Include /private/etc/apache2/extra/httpd-vhosts.conf”, then save.
taken from this tutorial which is priceless:
http://kevchapman.co.uk/development/setting-up-apache-on-snow-leopard/
I think its because youre using
ServerAlias *.domain.com
on both virtual hosts
since the ServerAlias directive indicates that the listed names are other names which people can use to see that same web site:
ServerAlias *.subdomain.com
then requests for all hosts in the subdomain.com domain will be served by the subdomain1.domain.com virtual host.
this might help http://httpd.apache.org/docs/2.0/vhosts/name-based.html
Related
I have two websites in the same web server (Ubuntu 16.04.2 LTS - Apache/2.4.18). Everything works well when I try to access to both websites using HTTP (port 80). This is the vhosts.conf file content:
<VirtualHost *:80>
ServerName site1
DocumentRoot /var/www/html/site1
ErrorLog ${APACHE_LOG_DIR}/site1_error.log
CustomLog ${APACHE_LOG_DIR}/site1_access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName site2
DocumentRoot /var/www/html/site2
ErrorLog ${APACHE_LOG_DIR}/site2_error.log
CustomLog ${APACHE_LOG_DIR}/site2_access.log combined
</VirtualHost>
So, both sites are accessible through "mydomain.com/site1" and "mydomain.com/site2". I have installed a Let's Encrypt certificate and, to make it works, I have configured a virtual host like this:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName mydomain.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/site_error.log
CustomLog ${APACHE_LOG_DIR}/site_access.log combined
SSLCertificateFile /etc/letsencrypt/live/mydomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
I can access both site using SSL (port 443) successfully but I can't use different log files for different sites. I have tried something like this:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName mydomain.com/site1
DocumentRoot /var/www/html/site1
ErrorLog ${APACHE_LOG_DIR}/site1_error.log
CustomLog ${APACHE_LOG_DIR}/site1_access.log combined
Alias /site1 /var/www/html/site1
SSLCertificateFile /etc/letsencrypt/live/mydomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
<VirtualHost *:443>
ServerName mydomain.com/site2
DocumentRoot /var/www/html/site2
ErrorLog ${APACHE_LOG_DIR}/site2_error.log
CustomLog ${APACHE_LOG_DIR}/site2_access.log combined
Alias /site2 /var/www/html/site2
SSLCertificateFile /etc/letsencrypt/live/mydomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
But it doesn't work. How can I distinguish between two sites in order to have two different log files?
Following the link proposed by CBroe, I have found the solution by using the SetEnvIf directive. The final working virtual host configuration looks like this:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName mydomain.com
DocumentRoot /var/www/html
SetEnvIf Request_URI ^/site1(/|$) site1
SetEnvIf Request_URI ^/site2(/|$) site2
CustomLog ${APACHE_LOG_DIR}/site1_access.log combined env=site1
CustomLog ${APACHE_LOG_DIR}/site2_access.log combined env=site2
ErrorLog ${APACHE_LOG_DIR}/site_error.log
SSLCertificateFile /etc/letsencrypt/live/mydomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
I get slightly crazy :)
I have a domain example.com and I have a SSL certificate for www.example.com
The example.com refers to the IP address of the server (it is an EC2 instance).
In the vhost.conf of the Server I have the following entries
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
<VirtualHost _default_:443>
ServerName www.example.com
DocumentRoot /var/www/vhosts/example-wp
SSLEngine On
...
</VirtualHost>
I took the information from the apache wiki.
https://wiki.apache.org/httpd/RedirectSSL
Thanks for helping
Tristan
You already have the necessary directives listed to perform the redirect. You also need to tell the vhost file where your certificate and key for the certificate exist. You also need to say whether or not a directory the user browses to is to load SSL. Please see a full example configuration file below.
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
Redirect / https://www.example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName www.example.com
ServerAlias example.com
ServerAdmin webmaster#local
DocumentRoot /path/to/web/content
DirectoryIndex index.php index.html
ErrorLog logs/error_log
CustomLog logs/access combined
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /etc/apache2/ssl.crt/certfile.cer
SSLCertificateKeyFile /etc/apache2/ssl.key/keyfile.key
<Directory "/path/to/web/content/">
Options None
AllowOverride None
Order allow,deny
Allow from all
SSLRequireSSL
</Directory>
</VirtualHost>
I'm not 100% familiar how htpasswd works, but i'm wondering if it is possible.
I have one server with one IP and multiple domains there. I need to password protect all of those domains but if possible only at one place. I don't want to go around and make htpasswd for each website.
Assuming that i have all websites places under /var/www/{vhost dirs}
Is it possible at all and how and how?
Multiple domain on single IP is possible from virtual host configuration in apache.
E.g I am running few domains on single machine :
www.internationalworkersday.com
www.internationallabourday.com
www.internationlaborday.com
www.internationalworkersday.org
www.apnok.com
#Here is virtual host configuration in httpd.conf
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
<VirtualHost *:80>
ServerAdmin www.apnok.com
DocumentRoot /home/ap/
ServerName www.apnok.com
ServerAlias apnok.com *.apnok.com
ErrorLog logs/error_log
CustomLog logs/access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin www.internationalworkersday.com
DocumentRoot /home/iwd/
ServerName www.internationalworkersday.com
ServerAlias internationalworkersday.com
ErrorLog logs/error_log
CustomLog logs/access_log_iwd common
</VirtualHost>
<VirtualHost *:80>
# ServerAdmin www.internationallabourday.com
DocumentRoot /home/ild/
ServerName www.internationallabourday.com
ServerAlias internationallabourday.com
# ErrorLog logs/error_log
#CustomLog logs/access_log_ild common
RewriteEngine On
RewriteCond %{HTTP_HOST} ^internationallabourday\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ http://www.internationalworkersday.com
#DirectoryIndex index.php index.php.var
</VirtualHost>
<VirtualHost *:80>
ServerAdmin www.internationallaborday.com
DocumentRoot /home/ila/
ServerName www.internationallaborday.com
ServerAlias internationallaborday.com
ErrorLog logs/error_log
CustomLog logs/access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin www.internationalworkersday.org
DocumentRoot /home/iwd/
ServerName www.internationalworkersday.org
ServerAlias internationalworkersday.org
ErrorLog logs/error_log
CustomLog logs/access_log_org common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin www.internationallabourday.org
DocumentRoot /home/ild/
ServerName www.internationallabourday.org
ServerAlias internationallabourday.org
ErrorLog logs/error_log
CustomLog logs/access_log_org common
</VirtualHost>
I've got a site set up on localhost that I'm actively developing, and I'd like to set up a subdomain on localhost to make my life 10* easier.
I added this to C:\xampp\apache\conf\extra\httpd-vhosts.conf:
<VirtualHost i1.localhost:80>
ServerAdmin dummy#localhost
DocumentRoot "C:/xampp/htdocs/i1/"
ServerName i1.localhost
ServerAlias www.i1.localhost
ErrorLog "logs/dummy-host2.localhost-error.log"
CustomLog "logs/dummy-host2.localhost-access.log" combined
</VirtualHost>
Apache stats up fine, but when I navigate to http://localhost/ I'm seeing content from the i1 subdomain. http://i1.localhost/ works fine, however.
Then I tried doing this:
<VirtualHost localhost:80>
ServerAdmin dummy#localhost
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
ServerAlias www.localhost
ErrorLog "logs/dummy-host2.localhost-error.log"
CustomLog "logs/dummy-host2.localhost-access.log" combined
</VirtualHost>
<VirtualHost i1.localhost:80>
ServerAdmin dummy#localhost
DocumentRoot "C:/xampp/htdocs/i1/"
ServerName i1.localhost
ServerAlias www.i1.localhost
ErrorLog "logs/dummy-host2.localhost-error.log"
CustomLog "logs/dummy-host2.localhost-access.log" combined
</VirtualHost>
But that worked the opposite. On both localhost and i1.localhost I'm seeing content from C:/xampp/htdocs/.
Anyone got an idea what's going wrong?
Cheers.
Apache usually does not like a vhosts document root inside another vhost, try:
DocumentRoot "C:/xampp/htdocs/"
and
DocumentRoot "C:/xampp/i1/"
I have an odd situation where I want to have the URLs app1.example.com, example.com and *.example.com all using a different virtual host. This is what I have (excluding example.com because it just makes it messier).
<VirtualHost *>
ServerName app1.example.com
ServerAlias app1.example.com
DocumentRoot = /var/www/app1
# Other configuration for this app here
</VirtualHost>
<VirtualHost *>
ServerName wildcard.example.com
ServerAlias *.example.com
DocumentRoot = /var/www/wildcard
# other configuration for this app here
</VirtualHost>
The problem is that they conflict. Whichever one is listed first wins out. How can I host both a wildcard virtualhost and a specific one?
Note: I'm not just changing DocumentRoot in the config, so using mod_rewrite to change the DocumentRoot variable does not fix it.
<VirtualHost *:80>
DocumentRoot /var/www/app1
ServerName app1.example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/example
ServerName example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/wildcard
ServerName other.example.com
ServerAlias *.example.com
</VirtualHost>
Should work. The first entry will become the default if you don't get an explicit match. So if you had app.otherexample.com point to it, it would be caught be app1.example.com.
Wildcards can only be used in the ServerAlias rather than the ServerName. Something which had me stumped.
For your use case, the following should suffice
<VirtualHost *:80>
ServerAlias *.example.com
VirtualDocumentRoot /var/www/%1/
</VirtualHost>
This also works for https needed a solution to making project directories this was it. because chrome doesn't like non ssl anymore used free ssl. Notice: My Web Server is Wamp64 on Windows 10 so I wouldn't use this config because of variables unless your using wamp.
<VirtualHost *:443>
ServerAdmin test#test.com
ServerName test.com
ServerAlias *.test.com
SSLEngine On
SSLCertificateFile "conf/key/certificatecom.crt"
SSLCertificateKeyFile "conf/key/privatecom.key"
VirtualDocumentRoot "${INSTALL_DIR}/www/subdomains/%1/"
DocumentRoot "${INSTALL_DIR}/www/subdomains"
<Directory "${INSTALL_DIR}/www/subdomains/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>