Multiple domains mixed up with SSL configuration with Apache httpd - apache

I have two domains and 1 IP address. In my httpd.conf file, I added,
<VirtualHost *:80>
ServerName www.domain1.com
ServerAlias domain1.com
Redirect permanent / https://www.domain1.com/
</VirtualHost>
<VirtualHost *:80>
ServerName www.domain2.com
ServerAlias domain2.com
Redirect permanent / https://www.domain2.com/
</VirtualHost>
There are some cases that domain2 URLs are redirected to domain1 (pay attention to the url protocols).
For example, on iPhone/Safari,
http://www.domain2.com
http://domain2.com
will both be redirected to https://www.domain1.com
On Windows using MSIE,
http://domain2.com
will both be redirected to https://www.domain1.com
http://www.domain2.com works fine.
On Windows using Chrome, most of the cases work except,
https://domain2.com will be considered insecure.
So this looks like a browser problem. Is there a way to prevent this from happening reliably?
Thanks.

You can do this (it works for me):
<VirtualHost *:80>
ServerName example1.com
ServerAlias example1.com
ProxyRequests off
ProxyPass / http://127.0.0.1:9090/
ProxyPassReverse / http://127.0.0.:9090/
</VirtualHost>
<VirtualHost *:80>
ServerName example2.com
ServerAlias example2.com
ProxyRequests off
ProxyPass / http://127.0.0.1:9091/
ProxyPassReverse / http://127.0.0.1:9091/
</VirtualHost>

Related

Ubuntu Apache Redirect All Request to HTTPS except Jenkins

I am creating a configuring a Server using Ubuntu and Apache. Everything works fine except that when I use redirection of HTTP to HTTPS.
How can I write an exception case where every http request is redirected to HTTPS except when its for JENKINS.
JENKINS : http://www.example.com:8080/ <= SHould not be redirected to HTTPS
Normal Request : http://www.example.com/ <= Should be redirected to HTTPS
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
<VirtualHost _default_:443>
ServerName example.com
DocumentRoot /usr/local/apache2/htdocs
SSLEngine On
# etc...
</VirtualHost>
Your sample configuration looks almost correct. You can create a separate VirtualHost for port 8080.
<Virtualhost *:8080>
ServerName example.com
.
.
ProxyPass / http://jenkins:8080/
.
.
</Virtualhost>
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
<VirtualHost _default_:443>
ServerName example.com
DocumentRoot /usr/local/apache2/htdocs
SSLEngine On
# etc...
</VirtualHost>

Apache Redirect with subdirectories

This is my current setup:
<VirtualHost *:443>
ServerName www.product.com
Redirect "/something" "https://www.anotherredirectwebsite.com.com/something-name-product"
RedirectPermanent / https://www.redirectsite.com/
Include includes/product-config.inc
# Enable SSL
Include ssl-conf/product_ssl.conf
</VirtualHost>
# Redirect non-www to wwww
<VirtualHost *:443>
ServerName product.com
RedirectPermanent / https://www.product.com/
Include ssl-conf/product_ssl.conf
</VirtualHost>
# Redirect non-www http to https
<VirtualHost *:80>
ServerName product.com
RedirectPermanent / https://www.product.com/
</VirtualHost>
# Redirect www http to https
<VirtualHost *:80>
ServerName www.product.com
Define proxy_host www.product.com
RedirectPermanent / https://www.product.com/
</VirtualHost>
I want everyone going to product.com to be redirected to a certain website. However when someone goes to product.com/something I want them to be redirected to a different website.
Problem now is that product.com/anysubdirectory will not be redirected, but the original site is shown. And this also causes the /something to not be redirected as well.
try this
<VirtualHost *:80>
ServerName product.com
ServerAlias www.product.com
RedirectPermanent / https://www.product.com/
</VirtualHost>
<VirtualHost *:443>
ServerName product.com
ServerAlias www.product.com
RewriteEngine On
RewriteRule ^something/(.*) https://www.anotherredirectsite.com/something-name-product/$1 [R=301,L]
RedirectPermanent / https://www.redirectsite.com/
# SSL config
</VirtualHost>

Apache proxy forward wildcard subdomain to tomcat

How do I setup the virtual host to forward the subdomin part to my tomcat.
I know * does not work....but how do I achieve something as below.
<VirtualHost *:80>
ProxyPreserveHost On
ServerName *.example.com
ProxyPass /app1 *.localhost:8080/app1
</VirtualHost>
Well that was a stupid question, the
ProxyPreserveHost On
by itself will preserve the original request so I don't have to forward the subdomain.
just the below will work..
<VirtualHost *:80>
ProxyPreserveHost On
ServerName *.example.com
ProxyPass /app1 http://localhost:8080/app1
</VirtualHost>
and my code actually sees http://subdomain.example.com/app1
Use one specific servername (perhaps "dummy"), then use the wildcard in a
ServerAlias statement:
<VirtualHost *:80>
ProxyPreserveHost On
ServerName dummy.example.com
ServerAlias *.example.com
ProxyPass /app1 *.localhost:8080/app1
</VirtualHost>

Apache redirect to perl script

I'm currently using Apache's vhosts configuration to redirect request to the server, e.g.
<VirtualHost IP:80>
ServerName http://domain.info
Redirect / http://otherdomain.com
</VirtualHost>
<VirtualHost IP:80>
ServerName http://subdomain.domain.info
Redirect / http://domain:port
</VirtualHost>
Now I installed AWstats which can be started by using the command
http://localhost/cgi-bin/awstats.pl
I assume that if I add this block to vhosts
<VirtualHost IP:80>
ServerName http://stats.domain.info
Redirect / http://domain.info/cgi-bin/awstats.pl
</VirtualHost>
I can remote-access AWstats using
http://domain.info/cgi-bin/awstats.pl
but all I get is
http://otherdomain.comcgi-bin/awstats.pl
What am I doing wrong?
Greetz
holgrich
The question is still open, but for now I used a workaround:
<VirtualHost IP:80>
ServerName http://domain.info
[Redirect to local html that contains frame forwarding]
</VirtualHost>
<VirtualHost IP:80>
ServerName http://subdomain.domain.info
Redirect / http://domain:port
</VirtualHost>
Now this works
<VirtualHost IP:80>
ServerName http://stats.domain.info
Redirect / http://domain.info/cgi-bin/awstats.pl
</VirtualHost>
So that I can remote-access AWstats using
http://domain.info/cgi-bin/awstats.pl

Redirect http to https by configuring .conf file of apache

I have configure apache to tomcat configuration by code like
<VirtualHost *:80>
ServerName captiveportal
ProxyPass / http://ip:port/path
ProxyPassReverse / http://ip:port/path
</VirtualHost>
Now i want to reirect this request to https
How can i achieve this ?
After looking your answer i have changes my configuration like
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile "/etc/httpd/conf/crt1.crt"
SSLCertificateKeyFile "/etc/httpd/conf/key1.key"
ProxyPass / http://ip:port/path
</VirtualHost>
<VirtualHost *:80>
ServerName captiveportal
Redirect / https://ip:port/path
</VirtualHost>
but when i type captiveportal on my browser it redirects me on url https://ip:port/path and it displays problem loading page
One more thing i don't want to display https://ip:port/path on browser.
Note :- https://ip:port/path where port is my tomcat port and ip is machine ip where tomcat run.
You could do something like this:
<VirtualHost *:80>
ServerName captiveportal
Redirect / https://my.host.name/
</VirtualHost>
...and then put your ProxyPass directives in side your SSL VirtualHost block instead.