Discussion:
Question on more concise httpd.conf setup for subdomain + https redirects
(too old to reply)
Ryan Flannery
2017-12-22 02:37:30 UTC
Permalink
Raw Message
Hi, I'm curious if there's a more concise/preferred way to accomplish the
below. I'm hosting a number of sites that want to prefer https over http
and strip any www subdomain from urls.

E.g.
www.foo.com/* -> https://foo.com/*
https://www.foo.com/* -> https://foo.com/*

I have this working (used acme-client to setup ssl - that was a breeze!)
using the following setup, but I'm curious if there's a more
concise/preferred way. I'll need to configure this for a number of sites,
and would probably script the config.

The first two server blocks setup the redirects, and the third is for the
actual site.

server "foo.net" {
alias "www.foo.net"
listen on * port 80
block return 301 "https://foo.net$REQUEST_URI"
}
server "www.foo.net" {
listen on * tls port 443
tls certificate "/etc/ssl/foo.net.fullchain.pem"
tls key "/etc/ssl/private/foo.net.key"
block return 301 "https://foo.net$REQUEST_URI"
}
server "foo.net" {
listen on * tls port 443
tls certificate "/etc/ssl/foo.net.fullchain.pem"
tls key "/etc/ssl/private/foo.net.key"
root "/htdocs/foo.net"
}

Cheers,
-Ryan
Andreas Thulin
2017-12-22 17:00:50 UTC
Permalink
Raw Message
Hi!

I suppose you can script one config into ”httpd.foo.net”, another to ”
httpd.bar.com” etc. and then include all individual files into httpd.conf
with the keyword ”include”?

BR, Andreas
Post by Ryan Flannery
Hi, I'm curious if there's a more concise/preferred way to accomplish the
below. I'm hosting a number of sites that want to prefer https over http
and strip any www subdomain from urls.
E.g.
www.foo.com/* -> https://foo.com/*
https://www.foo.com/* -> https://foo.com/*
I have this working (used acme-client to setup ssl - that was a breeze!)
using the following setup, but I'm curious if there's a more
concise/preferred way. I'll need to configure this for a number of sites,
and would probably script the config.
The first two server blocks setup the redirects, and the third is for the
actual site.
server "foo.net" {
alias "www.foo.net"
listen on * port 80
block return 301 "https://foo.net$REQUEST_URI"
}
server "www.foo.net" {
listen on * tls port 443
tls certificate "/etc/ssl/foo.net.fullchain.pem"
tls key "/etc/ssl/private/foo.net.key"
block return 301 "https://foo.net$REQUEST_URI"
}
server "foo.net" {
listen on * tls port 443
tls certificate "/etc/ssl/foo.net.fullchain.pem"
tls key "/etc/ssl/private/foo.net.key"
root "/htdocs/foo.net"
}
Cheers,
-Ryan
Loading...