I have a problem whereby my VirtualHost is overriding another VirtualHost on the same domain.
httpd.conf
IncludeOptional conf.d/*.conf
example.conf
<VirtualHost *:80>
DocumentRoot /var/www/html/example/
ServerName www.example.com
ServerAlias www.example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /var/www/html/example/
SSLEngine on
SSLCertificateFile /etc/httpd/ssl/example/example.crt
SSLCertificateKeyFile /etc/httpd/ssl/example/example.key
SSLCertificateChainFile /etc/httpd/ssl/example/chain.cer
ServerName www.example.com
ServerAlias www.example.com
</VirtualHost>
get.example.conf
<VirtualHost *:80>
DocumentRoot /var/www/html/get.example/
ServerName get.example.com
ServerAlias get.example.com
</VirtualHost>
When I created get.example.conf and when I accessed example.com, it is showing the content of get.example.com
Does anyone knows what is going wrong with my configuration?
Found out that I need to include the non-www for the VirtualHost as well. It works if I entered www.example.com but not example.com.
<VirtualHost *:80>
ServerName example.com
Redirect permanent / http://www.example.com/
</VirtualHost>
You just have to set up de ServerAlias.
In your example, it should be enough to do as follow:
<VirtualHost *:80>
DocumentRoot /var/www/html/example/
ServerName example.com
ServerAlias www.example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
Note that ServerName doesn't has www., so that it's gonna match http://example.com, while with the ServerAlias it's gonna match http://www.example.com
Try to change the order of ServerName and ServerAlias to your get.example.conf:
<VirtualHost *:80>
ServerName get.example.com
ServerAlias get.example.com
DocumentRoot /var/www/html/get.example/
</VirtualHost>
Related
This is what I basically have now:
<VirtualHost *:80>
DocumentRoot /var/www/app1
ServerName app1.example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/example
ServerName example.com
ServerAlias *.example.com
</VirtualHost>
This configuration makes app1.example.com a default serving VirtualHost.
Thus, when another.domain.com is pointed to *.example.com, it is served by app1.example.com.
How this configuration can be changed, so that another.domain.com would be served by *.example.com, still having app1.example.com, *.example.com and example.com working too?
Thank you.
P.S. I'm basing somewhat my question on this SO answer
My own research gave me the only workaround so far. I've ended up using another port for app1.example.com.
<VirtualHost *:8080>
DocumentRoot /var/www/app1
ServerName app1.example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/example
ServerName example.com
ServerAlias *.example.com
</VirtualHost>
Say, I have a domain http://www.example.com. I have this in httpd.conf: DocumentRoot "/Apache22/htdocs".
I also have /Apache22/htdocs/dir1 application directory, which I want to force users to connect to with https, say, with URL: https://www.example.com/dir1 and redirect any http requests to https for this directory.
I tried VirtualHost and Redirect so:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /Apache22/htdocs/
</VirtualHost>
<VirtualHost *:80>
ServerName www.example.com/dir1
DocumentRoot /Apache22/htdocs/dir1
Redirect permanent /dir1 https://www.example.com/dir1
</VirtualHost>
NameVirtualHost *:443
<VirtualHost *:443>
ServerName www.example.com/dir1
DocumentRoot /Apache22/htdocs/dir1
SSLEngine on
SSLCertificateFile conf/ssl/server.cert
SSLCertificateKeyFile conf/ssl/server.key
</VirtualHost>
But apparently Apache ignores any subdrectories in ServerName, so both www.example.com and www.example.com/dir1 are the same in VirtualHost block, as far as Apache concerned.
How do I achieve an https redirect of any URL accessing dir1?
Try:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /Apache22/htdocs/
Redirect permanent /dir1 https://www.example.com/dir1
</VirtualHost>
NameVirtualHost *:443
<VirtualHost *:443>
ServerName www.example.com
DocumentRoot /Apache22/htdocs
SSLEngine on
SSLCertificateFile conf/ssl/server.cert
SSLCertificateKeyFile conf/ssl/server.key
</VirtualHost>
The ServerName directive takes a host name, not anything including a path component.
I have a valid IP, e.g. x.x.x.x, and a domain, e.g. site.com which point to x.x.x.x.
First, I need to redirect any request from port 80 to 443 (security issue).
Second, for every request sent to my IP, I want apache to show "Hello it's
working" (/var/www/index.html) and everyone request to my domain to show the real site.
I tried this, but it did not work:
<VirtualHost x.x.x.x:433>
ServerName x.x.x.x
ServerAlias x.x.x.x
DocumentRoot /var/www/
DirectoryIndex index.html
Options -Indexes
</VirtualHost>
<VirtualHost site.com:443>
...
</VirtualHost>
for redirection:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.yourdomain.com
Redirect / https://www.yourdomain.com
</VirtualHost>
<VirtualHost _default_:443>
ServerName www.yourdomain.com
DocumentRoot /usr/local/apache2/htdocs
SSLEngine On
# etc...
</VirtualHost>
for domain separation:
<VirtualHost *:80>
# This first-listed virtual host is also the default for *:80
ServerName www.example.com
ServerAlias example.com
DocumentRoot "/www/domain"
</VirtualHost>
<VirtualHost *:80>
ServerName other.example.com
DocumentRoot "/www/otherdomain"
</VirtualHost>
Any reason why the middle vhost setting is causing an issue w/ Apache? Maybe it's because I don't have the SSL details in there?
<VirtualHost *:80>
ServerName www.windfarmstudios.com
ServerAlias windfarmstudios.com
Redirect permanent / https://windfarmstudios.com
</VirtualHost>
#<VirtualHost *:443>
# ServerName www.windfarmstudios.com
# Redirect permanent / https://windfarmstudios.com
#</VirtualHost>
<VirtualHost *:443>
ServerName windfarmstudios.com
DocumentRoot /var/www/windfarmstudios.com/public_html
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/windfarm.crt
SSLCertificateKeyFile /etc/apache2/ssl/windfarm.key
SSLCACertificateFile /etc/apache2/ssl/windfarm.ca-bundle
</VirtualHost>
I am trying to setup a virtual host. I have done this many times before on different servers with no problem, however, I have never tried it using a subdomain.
For some strange reason when I go to the subdomain: sub.mysite.co.uk I get redirected to the /var/www/mysite directory and not /var/www/other-site
Here is my apache.conf file:
Include /etc/apache2/sites-enabled/
NameVirtualHost *:80
<ifmodule mod_ssl.c>
NameVirtualHost *:443
</ifmodule>
<VirtualHost *:80>
ServerName *.mysite.co.uk
DocumentRoot "/var/www/newsletters/"
</VirtualHost>
And my sites-enabled file:
<VirtualHost *:80>
ServerName mysite.co.uk
DocumentRoot /var/www/newsletters
ServerAlias sub.mysite.co.uk
</VirtualHost>
Have I missed something?
Did you check your DNS entries? Maybe it's redirecting all subdomains to mysite.co.uk.
Write this in httpd.conf
Include /etc/apache2/sites-enabled/*.conf
Listen *:80
Write this in custom-vhost.conf located in sites-enabled
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin contact#example.com
DocumentRoot /var/www/domain1
ServerName domain1.me
ServerAlias www.domain1.me
</VirtualHost>
<VirtualHost *:80>
ServerAdmin contact#example.com
DocumentRoot /var/www/domain2
ServerName domain2.com
ServerAlias www.domain2.com
</VirtualHost>
Hope it works