nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

forwarding https://www.xxx to https://xxx in lighttpd

This is a discussion on forwarding https://www.xxx to https://xxx in lighttpd within the Web servers forums, part of the Mastering Servers category; Hi, I am a bit stuck with how to get around lighttpd's insistence on IP-based virtual hosting when using SSL. ...


Go Back   nixCraft Linux Forum > Mastering Servers > Web servers

Linux answers from nixCraft.


Web servers Discussion on Apache, Nginx and Lighttpd HTTP/web server and configuration issues.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-10-2009, 08:44 PM
Junior Member
User
 
Join Date: Oct 2009
OS: Centos 5.2
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
simonjwoolf is on a distinguished road
Default forwarding https://www.xxx to https://xxx in lighttpd

Hi,

I am a bit stuck with how to get around lighttpd's insistence on IP-based virtual hosting when using SSL.

I have an SSL site up and running with the following configuration:
$SERVER["socket"] == "111.111.111.111:443" {
ssl.engine = "enable"
ssl.pemfile = "/etc/lighttpd/ssl.key/mydomain.com.pem"
....
}

So the site URL is https://mydomain.com/

But... I want to forward any requests for https://www.mydomain.com to https://mydomain.com
as otherwise visitors will get a warning as the SSL cert will be invalid.

I can't find any way to do this - I've tried nesting an HTTP["host"] block inside
the SERVER["socket"] block, but it looks like this doesn't function at all if
the site is SSL. I also tried using HTTP["url"] but that didn't work either.

Help!

Simon.

Centos 5.2
Lighttpd 1.4.18

Serving up Django via FastCGI
Reply With Quote
  #2 (permalink)  
Old 07-10-2009, 09:10 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,709
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Add the following lines to lighttpd.conf or your virual hosting section
Code:
$HTTP["host"] =~ "^www\.(.*)" {   url.redirect = ( "^/(.*)" => "https://%1/$1" ) }
Reload / restart lighttpd. I've same config here on this forum. If you visit http://www.nixcraft.com/ it will move to http://nixcraft.com/

HTH
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 07-10-2009, 09:13 PM
Junior Member
User
 
Join Date: Oct 2009
OS: Centos 5.2
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
simonjwoolf is on a distinguished road
Default

Not quite!

I'm well aware of how to redirect http to https, but what I am asking here is how to redirect https://somevalue to https://some_other_value

This seems to be more difficult.
Reply With Quote
  #4 (permalink)  
Old 07-10-2009, 09:16 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,709
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

I'm sorry I cannot follow you. Can you be more specific and please add your example urls in [code] tags so that I can see it. Otherwise VB is "Automatically parsing links in text" and "automatically retrieving titles from external links"
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #5 (permalink)  
Old 07-10-2009, 09:25 PM
Junior Member
User
 
Join Date: Oct 2009
OS: Centos 5.2
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
simonjwoolf is on a distinguished road
Default

OK, so I want all of the following options to forward to
Code:
https://sub.mydomain.com/
Code:
http://sub.mydomain.com/
Code:
http://www.sub.mydomain.com/
Code:
https://www.sub.mydomain.com/
Currently I have this in my config to handle the http > https redirects:

Code:
 
        $HTTP["host"] =~ "^(www\.)?sub\.mydomain\.com$" {
                url.redirect = ( "^/(.*)" => "https://sub.mydomain.com/$$
                server.name     = "sub.mydomain.com"
        }
But I want to know how I can handle the https > https redirect.
Reply With Quote
  #6 (permalink)  
Old 07-10-2009, 09:27 PM
Junior Member
User
 
Join Date: Oct 2009
OS: Centos 5.2
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
simonjwoolf is on a distinguished road
Default

Sorry it still formatted in a way which wasn't clear!

This is the main https domain:

Code:
https://sub.mydomain.com
All the others are options which should be forwarded.
Reply With Quote
  #7 (permalink)  
Old 07-10-2009, 09:37 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,709
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Now, I get it you want to match all http requests including subdomains and redirect them to https domains. I had something as follows for one my domain. It redirect everything from http://example.com to http://sub.example.com to https://example.com
Code:
$SERVER["socket"] == ":80" {
  $HTTP["host"] =~ "(.*)" {
    url.redirect = ( "^/(.*)" => "https://%1/$1" )
  }
}
Since I've not seen your lighttpd.conf. Above is what you needed, IMHO. Keep in mind you need to modify port 80 config and then it will work. Try out and let me know...
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #8 (permalink)  
Old 07-10-2009, 09:40 PM
Junior Member
User
 
Join Date: Oct 2009
OS: Centos 5.2
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
simonjwoolf is on a distinguished road
Default

Nope, the devil is in the detail!

I know how to forward from http to https

I am having a problem forwarding from one https address to another!

It's this url
Code:
https://www.sub.mydomain.com/
which should forward to
Code:
https://sub.mydomain.com/
that I am struggling with
Reply With Quote
  #9 (permalink)  
Old 07-10-2009, 10:45 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,709
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Try selecting and matching https with $HTTP["scheme"] directive:
Code:
$HTTP["scheme"] == "https" {
    ....
}
Example:
Code:
$HTTP["scheme"] == "https" {
        url.redirect = ("^/(isoimages/.*)" => "https://%1/$1")
}
This only works with lighttpd version 1.4.19 or above.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help

Last edited by nixcraft; 08-10-2009 at 01:00 AM.
Reply With Quote
  #10 (permalink)  
Old 07-10-2009, 11:14 PM
Junior Member
User
 
Join Date: Oct 2009
OS: Centos 5.2
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
simonjwoolf is on a distinguished road
Default

OK, I'm currently on 1.4.18 so when I get the chance to upgrade I'll give this a shot - thanks!
Reply With Quote
Reply

Tags
https , lighttpd , lighttpd http to https redirection , lighttpd ssl redirection , ssl , virtual hosting


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Linux IP forwarding varunkant Linux software 2 08-07-2008 04:15 PM
DNS: Conditional Forwarding marros Getting started tutorials 1 04-07-2008 01:36 AM
Port forwarding satimis Networking, Firewalls and Security 0 02-02-2008 07:45 AM
https error surmandal Web servers 0 11-10-2007 12:22 PM
SSH via HTTPs ? rcordeiro Linux software 5 23-06-2006 05:42 PM


All times are GMT +5.5. The time now is 06:47 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38