Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a Hudson/Jenkins installation which runs on port 443, so I can access it with https://ci.mydomain.com. I do not have a webserver running on port 80 like Apache Httpd, but I want if a user types http://ci.mydomain.com it should be redirected to https://...

I tried it with iptables:

/sbin/iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 443
/sbin/iptables-save
chkconfig --level 35 iptables on

But the browser tells me, that the connection failed. So I do not want to install Apache webserver, I only want to have a redirect from http://ci.mydomain.com to https://ci.mydomain.com.

share|improve this question

marked as duplicate by Katherine Villyard, mdpc, Avery Payne, Falcon Momot, dawud Feb 15 at 11:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Okay I have to install sth. like Apache. And then, what is the best way to redirect? –  Tim Jun 8 '11 at 15:59
add comment

6 Answers

If this is a follow-up of this question, the problem is that you're trying to run Jenkins on a privileged port (<1024). You're mixing things up with port 80 and 443 in your question here.

Run Jenkins on port 8443 (which is usual for an unprivileged HTTPS port) and use iptables to redirect from/to 443 and 8443.

To redirect from http:// to https://, Apache and mod_rewrite is a good choice, as others have suggested. Alternatively, any tiny web server should be able to send a redirect (HTTP 301 or 302 status) with a Location header.

share|improve this answer
add comment

Setup a relatively blank VirtualHost listening on 80, which does nothing but

RewriteEngine On

RewriteRule (.*) https://foo.com$1

share|improve this answer
add comment

iptables IS NOT what you want here -- You are sending a browser that is expecting to talk plain-old HTTP (just boring ordinary text) to a server that is talking HTTPS (encrypted, and VERY confusing for your browser).

You want a 300-series Redirect issued by your web server to send the client to the appropriate https:// URL. If you are running Apache you can combine this with the SSLRequireSSL directive (Manual Entry) to ensure that your clients cannot access resources that should be encrypted over unencrypted channels.

share|improve this answer
add comment

Going from http to https is more then just switching ports. These are two different protocols and your Hudson/Jenkins installation is looking for https and not http.

I don't know of a way to do what you want without installing something like Apache to listen on port 80.

share|improve this answer
add comment

You are probably at an impasse here as http & https are dissimilar enough where a simple port redirect is not going to work.

share|improve this answer
add comment

HTTP and HTTPS are different application level protocols, so you can't just redirect on a transport level. You should set up Apache or Nginx or something on port 80 to perform a proper HTTP redirect using a Location header.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.