I have a HTTP and HTTPS load balancer on Goole Cloud. Is it possible to set it up to enforce (redirect) all connections to HTTPS?
Not at the load balancer as of June 2015.
As an alternative, you can configure your web servers to return 301 for all HTTP requests redirecting to the HTTPS version.
For Apache (from https://wiki.apache.org/httpd/RedirectSSL):
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
<VirtualHost _default_:443>
ServerName www.example.com
DocumentRoot /my/document/root
SSLEngine On
# .. etc .
</VirtualHost>
For nginx (from https://serverfault.com/questions/67316/in-nginx-how-can-i-rewrite-all-http-requests-to-https-while-maintaining-sub-dom):
server {
listen [::]:80;
return 301 https://$host$request_uri;
}
Why bother to redirect? You could easily create new (SSL) global forwarding rule and point it to your backend service.
For example, http://107.178.251.37/ points to my HTTP backend and I've added another global forwarding rule to make it SSL: https://107.178.240.233/.
Related
I have a site example.com and setup a VirtualHost to redirect to https://www.example.com
When I go to http://example.com it works great, however https does not
How can I update my VirtualHost configuration to also direct https traffic?
<VirtualHost *:80>
ServerName example.com
Redirect permanent "/" "https://www.example.com"
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
Redirect permanent "/" "https://www.example.com"
</VirtualHost>
The top one works great and redirects as expected, but https://example.com does not
Confirmed in AWS that the instance allows all traffic on both ports 80 and 443
--update
This is hosted on an AWS EC2 instance, and the HTTPS certificate in question was issued via the AWS Certificate Manager. Per Shim's suggestion I looked at https://wiki.apache.org/httpd/NameBasedSSLVHosts but it requires me to export a certificate which AWS does not permit? Is there another way around this?
i have installed SSL.
and trying to redirect all HTTP request to HTTPS.
i came across this code snippet,
<VirtualHost *:80>
ServerName www.example.com
Redirect / https://www.example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName www.example.com
# ... SSL configuration goes here
</VirtualHost>
i will add it at httpd.conf (i am using apache from the wamp bundle)
my question is what should be there in "# ... SSL Configuration goes here"
i am using AWS certificate manager with Elastic Load Balancer
Thanks
You need the http to https redirection in apache configuration.
my question is what should be there in "# ... SSL Configuration goes
here"?
You don't need to add any SSL configuration since you can attach the SSL certificate to the ELB with AWS Certificates Manager, while terminating the SSL connection at the ELB.
You can use http to communicate from ELB to the EC2 instance.
If you use AWS ELB at ELB https will get terminated so just needs to add ssl certs to ELB
note from ELB to your EC2 will not be under https(i.e ssl encrypted)
if you use https Refer AWS documentation
refer
for non AWS accounts
<VirtualHost *:443>
ServerName example.com
DocumentRoot "/var/www/html/"
SSLEngine on
SSLCertificateFile "/etc/ssl/certs/example.crt"
SSLCertificateKeyFile "/etc/ssl/certs/example.key"
My current setup is like this. I have a registered domain name. Through my domain provider I have pointed my domain to a dynamic IP address. So mysite.com points to 97.89.120.x
I have dd-wrt router and it is keeping my dynamic IP updated and port forwarding all port 80 and 443 request to my apache server IP of 192.168.121.50 ( Nothing real crazy here)
My apache server redirects all port 80 request to port 443
cat /etc/apache2/sites-available/default
<VirtualHost *:80>
RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
</VirtualHost>
cat /etc/apache2/sites-available/default-ssl
<VirtualHost _default_:443>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/mycloud
</VirtualHost>
This all works like a champ and is very straight forward.
I want to add a subdomain of cloud.mysite.com. So that mysite.com and cloud.mysite.com both point to the same dynamic IP 97.89.120.x From my dd-wrt router I am port forwarding all port 80 and 443 request to a new server in my environment 192.168.121.60
I want the apache server on this new host to host mysite.com and to forward request for cloud.mysite.com to the other server 192.168.121.50 and be redirected to https / ssl / ports 443.
So how exactly do I setup the virtual server to do this? I have tried similar to this without success.
NameVirtualHost *
<VirtualHost *:80>
ServerName www.mysite.com
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *:80>
ServerName www.cloud.mysite.com
ServerAlias 192.168.121.50
DocumentRoot /var/www/mycloud
</VirtualHost>
How can I redirect the subdomain to a different server and get this to work?
You have a wrong understanding of virtual hosts. The purpose of vhosts is to host multiple sites on a single webserver. It is not impossible to do this with your approach, but in the case that you have several webservers and services that you want to publish to the www in one domain, you will organize this in another way.
You can do this by DNS, Gateway, Reverse Proxing, Routing and maybe other approaches.
I suggest to find an approach where the ddwrt router will organize the requests and hand them to the desired webserver.
On ddwrt, just as example for a reverse proxy and loadbalancer, you can do this with Pound: http://www.dd-wrt.com/wiki/index.php/Pound
Please let me know if you have further questions. I will edit my post then. But this is from this point a question for serverfault and not for stackoverflow.
You will need to use 192.168.121.60 as a proxy of 192.168.121.50. But this may not be the best/smart way to achieve this. Proxying a web server for another ??
You already have setup for cloud.mysite.com on 192.168.121.60. Using mod_proxy_balancer ,this will look something like below.
<VirtualHost *:80>
ServerName www.cloud.mysite.com
ServerAlias cloud.mysite.com
ProxyRequests Off
<Proxy balancer://mycluster>
BalancerMember http://192.168.121.50
</Proxy>
ProxyPass / balancer://mycluster
</VirtualHost>
The best way as pointed out by #LukasF is to have both the sites hosted on a single web server.
Hope that helps!
I would like to:
redirect https requests for / to /sweetApp/
redirect all http requests to https
after the redirects, proxy requests to an internal ip address
I have set up these vhost rules. The http to https redirect works but the redirect to /sweetApp/ does not.
In the end, I would like an external request for sweetSite.com to proxy and redirect so the internal server only sees a request for 192.168.3.92:9080/sweetApp/
I am using Apache 2.4.3 so it should support name based ssl vhosts.
#Redirect to SSL
<VirtualHost *:80>
ServerName sweetSite.com
RedirectMatch ^/$ https://sweetSite.com/
</VirtualHost>
# The Real McCoy
<VirtualHost *:443>
ServerName sweetSite.com
#Map to /sweetApp/ by default
RedirectMatch ^/$ /sweetApp/
SSLEngine On
SSLProxyEngine On
SSLCertificateFile ssl/certificate.crt
SSLCertificateKeyFile ssl/certificate.key
#SSL to HTTP Proxy
ProxyPass / http://192.168.3.92:9080/
ProxyPassReverse / http://192.168.3.92:9080/
</VirtualHost>
The problem for me is that if there is a proxyPass rule, it takes precedence over any redirect rule.
Because I need this machine to do both the redirect and the proxy, the only solution I could find was to use mod_rewrite to "proxy" and to change the url to /sweetApp/.
I installed SSL (stupidly) to encrypt the data being sent, the only trouble was my subdomain was redirecting to my main. I changed my default virtual host back to the original settings and also typed a2dismod ssl. Now when ever I type in www.domain.com it redirects to https://www.domain.com and then says SSL Connection Error.
I'm hoping to either get SSL working on the main+sub or just remove completely. Has anyone got any idea why it's redirecting to Https?
My VirtualHosts file is:
<VirtualHost *:80>
ServerName www.domain.com
DocumentRoot /var/www/folder
#SSLEngine on
#SSLCertificationFile /etc/apache2/ssl/apache.crt
#SSLCertificationKeyFile /etc/apache2/ssl/apache.key
</VirtualHost>
<VirtualHost *:80>
ServerName sub.domain.com
DocumentRoot /var/www/sub
#SSLEngine on
#SSLCertificationFile /etc/apache2/ssl/apache.crt
#SSLCertificationKeyFile /etc/apache2/ssl/apache.key
</VirtualHost>
Now if I un-comment the lines with # on and change *:80 to *:443 it redirects to the main site with SSL enabled...
You are enabling mod_ssl (with the "SSLEngine on" directive) on a HTTP Virtual Host on TCP/80. You need to set up different Virtual Hosts bound to the TCP/443 port, on only enable mod_ssl on these.
Otherwise, mod_ssl expect an HTTPS connection on port 80 and, seeing that your browser is speaking HTTP, tries to redirect the browser to https://www.domain.com.