Redirect http to https by configuring .conf file of apache - 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.

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>

Use Proxy to redirect my Site?

I want to redirect my Apache Server to my node server running on other
port on localhost Like when i enter localhost:80 it should redirect my node server which is running on localhost:3000.
<VirtualHost *:3000>
ProxyPreserveHost On
ProxyRequests Off
ServerName www.example.com
ServerAlias example.com
ProxyPass / http://localhost:80/example/
ProxyPassReverse / http://localhost:80/example/
</VirtualHost>

Redirect a virtualhost http & https to another virtualhost server

I have 2 apache 2.4 serverA and serverB with several virtualhost. All incoming requests arrive on serverA.
How do I forward http and https request for a specific virtualhost name from serverA to serverB?
My wamp ServerA setup is:
into my hosts file
127.0.0.7 example.com
The virtualhost:
<VirtualHost *:*>
ServerName example.com
ProxyPreserveHost On
ProxyPass "/" "http://192.168.1.105/"
ProxyPassReverse "/" "http://192.168.1.105/"
</VirtualHost>
My serverB ip is 192.168.1.105 and I setup a virtual host on it with the same name example.com
when I use http://example.com I stay on the wamp home page like http://localhost
and when I use https://example.com I have error 403 (Forbidden) on serverA
After a long night, I find a solution:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass "/" "http://192.168.1.105/"
ProxyPassReverse "/" "http://192.168.1.105/"
ServerName example.com
</VirtualHost>
<VirtualHost *:443>
SSLProxyEngine on
SSLCertificateFile "${APACHE_DIR}/conf/ssl_example.com/server.crt"
SSLCertificateKeyFile "${APACHE_DIR}/conf/ssl_example.com/server.key"
ErrorLog "logs/example.com-ssl_error.log"
CustomLog "logs/example.com-ssl_access.log" common
ProxyPreserveHost On
ProxyPass "/" "https://192.168.1.105/"
ProxyPassReverse "/" "https://192.168.1.105/"
ServerName example.com
</VirtualHost>
in ServerA virtualhost add a simple:
Redirect / https://serverb.examample.com/

Apache Reverse proxy using hosts file

I have set up the following config for my apache server:
<VirtualHost *:80>
ServerName www.tld.com
ServerAlias *.tld.com
ProxyRequests On
ProxyPreserveHost On
RewriteEngine on
RewriteRule ^(.+) $1 [P]
ProxyPassReverse / $1
</VirtualHost>
<VirtualHost *:443>
ServerName www.tld.com
ServerAlias *.tld.com
ProxyRequests On
ProxyPreserveHost On
SSLEngine On
SSLCertificateFile /etc/ssl/certs/server.crt
SSLCertificateKeyFile /etc/ssl/private/server.key
ProxyPass / http://localhost/
ProxyPassReverse / http://localhost/
</VirtualHost>
And then I set up my host file to look like this:
127.0.0.1 tld.com
external_ip sub.tld.com
external_ip_2 sub.tld.com
external_ip and external_ip_2 are two servers that run apache and have vhosts as well. For the main domain I have a wildcard CSS and added a wildcard DNS record.
The proxying works perfect with HTTP and HTTPS as well, for all the servers that are in my /etc/hosts file. But it seems that when I try to resolve a subdomain that is not in my hosts file, apache get's stuck and in the logs I can see the following error:
[pid 4690] AH00161: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting
I think that there is an infinite loop and I don't know why this is caused. I consider that the page from the proxy server should be displayed if the subdomain is not resolved by the hosts file.
Shouldn't the ServerName be like the domain name, and the alias the www ? Like:
ServerName tld.com
ServerAlias www.tld.com
Seems a bit redundant to me to put the ServerName as a subdomain, an then add an alias with a wildcard.

Apache 2.2 and tomcat redirection for subdomains

I have two tomcat servers running in my machine and i want to use apache to redirect the traffic to each server depending on the subdomain.
My httpd.conf is:
<VirtualHost *:80>
ServerName dev.bo.example.com
ProxyPass / ajp://localhost:11009/bo/
ProxyPassReverse / ajp://localhost:11009/bo/
ProxyPassReverseCookiePath /bo/ http://localhost:11001/bo/
</VirtualHost>
<VirtualHost *:80>
ServerName dev.com.example.com
ProxyPass / ajp://localhost:10009/com/
ProxyPassReverse / ajp://localhost:10009/com/
ProxyPassReverseCookiePath /com/ http://localhost:10001/com/
</VirtualHost>
The problem is that the traffic is always direct to the first tomcat server despite the subdomain i use.
It seems that only the first virtual host match despite if i use:
http://dev.com.com.example.com/ or
http://dev.bo.example.com/
Does any know what i am missing here?
Finally, i found that i missed configuration i had to add
NameVirtualHost *:80
to the httpd.conf