Skip to content

Commit ab81956

Browse files
committed
feat(ocf_www): move nginx to 80/443, apache to backend-only
1 parent 452cb79 commit ab81956

File tree

9 files changed

+40
-242
lines changed

9 files changed

+40
-242
lines changed

modules/ocf_www/files/vhost-web-nginx.jinja

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# {{vhost.comment}}
2-
# CR-soon oliverni: move to 80/443
32

43
{% if vhost.ssl %}
54
server {
6-
listen 8443 ssl http2;
7-
listen [::]:8443 ssl http2;
5+
listen 443 ssl http2;
6+
listen [::]:443 ssl http2;
87
server_name "{{vhost.fqdn}}";
98

109
ssl_certificate {{vhost.ssl.bundle}};
@@ -32,15 +31,28 @@ server {
3231
{% endif %}
3332
}
3433

34+
{% for ws_location in vhost.websocket_locations %}
35+
location /{{ws_location}} {
36+
proxy_http_version 1.1;
37+
proxy_set_header Upgrade $http_upgrade;
38+
proxy_set_header Connection "Upgrade";
39+
proxy_set_header Host $host;
40+
proxy_set_header X-Forwarded-For $remote_addr;
41+
proxy_set_header X-Forwarded-Proto $scheme;
42+
proxy_set_header X-Real-IP $remote_addr;
43+
proxy_pass http://127.0.0.1:{{backend_port}};
44+
}
45+
{% endfor %}
46+
3547
access_log /var/log/nginx/vhost-access.log vhost;
3648
}
3749
{% endif %}
3850

3951
{% if not vhost.ssl or vhost.is_redirect %}
4052
# HTTP (redirect or non-SSL)
4153
server {
42-
listen 8080;
43-
listen [::]:8080;
54+
listen 80;
55+
listen [::]:80;
4456
server_name "{{vhost.fqdn}}";
4557

4658
location /.well-known/ {

modules/ocf_www/files/vhost-web.jinja

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
# {{vhost.comment}}
2-
{% set ports = [vhost.port, backend_port] if vhost.ssl else [vhost.port] %}
3-
{% for port in ports %}
4-
<VirtualHost *:{{port}}>
2+
<VirtualHost 127.0.0.1:{{backend_port}}>
53
ServerName {{vhost.fqdn}}
64
ServerAdmin {{vhost.contact_email}}
75

8-
{% if vhost.ssl and port != backend_port %}
9-
# SSL
10-
SSLEngine on
11-
SSLCertificateFile {{vhost.ssl.bundle}}
12-
SSLCertificateKeyFile {{vhost.ssl.key}}
13-
Protocols h2 http/1.1
14-
{% endif %}
15-
166
{% if vhost.is_redirect %}
177
RewriteEngine on
188
RewriteCond %{REQUEST_URI} !^/\.well-known/
@@ -29,7 +19,7 @@
2919
# Proxy to the local "unavailable" vhost, which serves up a friendly
3020
# "your website is rekt" page.
3121
RequestHeader set Host unavailable.ocf.berkeley.edu
32-
ProxyPass / http://127.0.0.1/
22+
ProxyPass / http://127.0.0.1:{{backend_port}}/
3323
{% else %}
3424
DocumentRoot {{vhost.docroot}}
3525

@@ -61,4 +51,3 @@
6151

6252
UserDir disabled
6353
</VirtualHost>
64-
{% endfor %}

modules/ocf_www/manifests/init.pp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,31 @@
1212
# www.ocf.berkeley.edu, which is by far the most complicated domain.
1313
#
1414
# Nginx sits in front of Apache for slowloris protection.
15-
# CR-soon oliverni: swap nginx to 80/443, apache to 127.0.0.1:$backend_port only
15+
# Nginx handles 80/443, Apache only listens on 127.0.0.1:$backend_port.
1616
class ocf_www {
1717
# Port Apache listens on as nginx's backend (plain HTTP on localhost).
1818
# Must match BACKEND_PORT in build-vhosts.
19-
# Phase 2: make this the only Apache port and bind to 127.0.0.1.
2019
$backend_port = 16767
20+
21+
# All Apache vhosts are backend-only (nginx handles 80/443).
22+
Apache::Vhost {
23+
ip => '127.0.0.1',
24+
port => $backend_port,
25+
}
26+
2127
include ocf::acct
2228
include ocf::extrapackages
2329
include ocf::firewall::allow_web
2430
include ocf::limits
2531
include ocf::tmpfs
2632
include ocf::ssl::default
2733

28-
# enables the http2 module
29-
apache::mod { 'http2': }
30-
3134
class { 'ocf::nfs':
3235
cron => false,
3336
web => false,
3437
}
3538

36-
# nginx reverse proxy (test ports for now)
39+
# nginx reverse proxy
3740
include ocf_www::nginx
3841

3942
class {
@@ -66,8 +69,9 @@
6669
backport_on => 'stretch';
6770
}
6871

69-
# Restart apache if any cert changes occur
70-
Class['ocf::ssl::default'] ~> Class['Apache::Service']
72+
# Apache no longer serves SSL directly (nginx handles it), but mod_ssl is
73+
# still needed for SSLProxyEngine (outbound HTTPS to apphost).
74+
include apache::mod::ssl
7175

7276
include ocf_www::lets_encrypt
7377
include ocf_www::logging

modules/ocf_www/manifests/nginx.pp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
# Nginx reverse proxy in front of Apache for slowloris protection.
2-
# CR-soon oliverni: move to 80/443, put apache on 127.0.0.1:$backend_port
32
#
43
# Static vhosts (www, shorturl, etc.) are defined here.
54
# Dynamic user vhosts come from build-vhosts via /etc/nginx/ocf-vhost.conf.
65
class ocf_www::nginx {
76
include ocf::ssl::default
8-
include ocf_www::nginx::firewall
97

10-
# CR-soon oliverni: change listen/ssl ports to 80/443
11-
$http_port = 8080
12-
$ssl_port = 8443
8+
$http_port = 80
9+
$ssl_port = 443
1310

1411
$backend = "http://127.0.0.1:${ocf_www::backend_port}"
1512

modules/ocf_www/manifests/nginx/firewall.pp

Lines changed: 0 additions & 12 deletions
This file was deleted.

modules/ocf_www/manifests/site/ocfweb_redirects.pp

Lines changed: 3 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,11 @@
2121
],
2222
}
2323

24-
apache::vhost { 'accounts':
25-
* => $accounts_options,
26-
port => 443,
27-
ssl => true,
28-
headers => ['always set Strict-Transport-Security max-age=31536000'],
29-
ssl_key => "/etc/ssl/private/${::fqdn}.key",
30-
ssl_cert => "/etc/ssl/private/${::fqdn}.crt",
31-
ssl_chain => "/etc/ssl/private/${::fqdn}.intermediate",
32-
}
33-
34-
# nginx backend (plain HTTP on localhost)
3524
apache::vhost { 'accounts-backend':
36-
* => $accounts_options,
37-
port => $ocf_www::backend_port,
38-
}
39-
40-
apache::vhost { 'accounts-http-redirect':
41-
servername => 'accounts.ocf.berkeley.edu',
42-
serveraliases => [
43-
'dev-accounts',
44-
'dev-accounts.ocf.berkeley.edu',
45-
'accounts',
46-
],
47-
port => 80,
48-
docroot => '/var/www/html',
49-
50-
redirect_status => 'permanent',
51-
redirect_dest => $accounts_canonical_url;
25+
* => $accounts_options,
5226
}
5327

5428
# wiki
55-
$wiki_canonical_url = $::host_env ? {
56-
'dev' => 'https://dev-wiki.ocf.berkeley.edu/',
57-
'prod' => 'https://wiki.ocf.berkeley.edu/',
58-
}
59-
6029
$wiki_options = {
6130
servername => 'wiki.ocf.berkeley.edu',
6231
serveraliases => ['dev-wiki.ocf.berkeley.edu'],
@@ -67,42 +36,11 @@
6736
],
6837
}
6938

70-
apache::vhost { 'wiki':
71-
* => $wiki_options,
72-
port => 443,
73-
ssl => true,
74-
headers => ['always set Strict-Transport-Security max-age=31536000'],
75-
ssl_key => "/etc/ssl/private/${::fqdn}.key",
76-
ssl_cert => "/etc/ssl/private/${::fqdn}.crt",
77-
ssl_chain => "/etc/ssl/private/${::fqdn}.intermediate",
78-
}
79-
80-
# nginx backend (plain HTTP on localhost)
8139
apache::vhost { 'wiki-backend':
82-
* => $wiki_options,
83-
port => $ocf_www::backend_port,
84-
}
85-
86-
apache::vhost { 'wiki-http-redirect':
87-
servername => 'wiki.ocf.berkeley.edu',
88-
serveraliases => [
89-
'dev-wiki',
90-
'dev-wiki.ocf.berkeley.edu',
91-
'wiki',
92-
],
93-
port => 80,
94-
docroot => '/var/www/html',
95-
96-
redirect_status => 'permanent',
97-
redirect_dest => $wiki_canonical_url;
40+
* => $wiki_options,
9841
}
9942

10043
# hello
101-
$hello_canonical_url = $::host_env ? {
102-
'dev' => 'https://dev-hello.ocf.berkeley.edu/',
103-
'prod' => 'https://hello.ocf.berkeley.edu/',
104-
}
105-
10644
$hello_options = {
10745
servername => 'hello.ocf.berkeley.edu',
10846
serveraliases => [
@@ -118,35 +56,7 @@
11856
],
11957
}
12058

121-
apache::vhost { 'hello':
122-
* => $hello_options,
123-
port => 443,
124-
ssl => true,
125-
headers => ['always set Strict-Transport-Security max-age=31536000'],
126-
ssl_key => "/etc/ssl/private/${::fqdn}.key",
127-
ssl_cert => "/etc/ssl/private/${::fqdn}.crt",
128-
ssl_chain => "/etc/ssl/private/${::fqdn}.intermediate",
129-
}
130-
131-
# nginx backend (plain HTTP on localhost)
13259
apache::vhost { 'hello-backend':
133-
* => $hello_options,
134-
port => $ocf_www::backend_port,
135-
}
136-
137-
apache::vhost { 'hello-http-redirect':
138-
servername => 'hello.ocf.berkeley.edu',
139-
serveraliases => [
140-
'dev-hello',
141-
'dev-hello.ocf.berkeley.edu',
142-
'dev-staff.ocf.berkeley.edu',
143-
'hello',
144-
'staff.ocf.berkeley.edu',
145-
],
146-
port => 80,
147-
docroot => '/var/www/html',
148-
149-
redirect_status => 'permanent',
150-
redirect_dest => $hello_canonical_url;
60+
* => $hello_options,
15161
}
15262
}

modules/ocf_www/manifests/site/shorturl.pp

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
class ocf_www::site::shorturl {
2-
$canonical_url = $::host_env ? {
3-
'dev' => 'https://dev-ocf-io.ocf.berkeley.edu/',
4-
'prod' => 'https://ocf.io/',
5-
}
6-
72
$shorturl_options = {
83
servername => 'ocf.io',
94
serveraliases => ['dev-ocf-io.ocf.berkeley.edu', 'www.ocf.io'],
@@ -171,30 +166,7 @@
171166
],
172167
}
173168

174-
apache::vhost { 'shorturl':
175-
* => $shorturl_options,
176-
port => 443,
177-
ssl => true,
178-
headers => ['always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"'],
179-
ssl_key => "/etc/ssl/private/${::fqdn}.key",
180-
ssl_cert => "/etc/ssl/private/${::fqdn}.crt",
181-
ssl_chain => "/etc/ssl/private/${::fqdn}.intermediate",
182-
}
183-
184-
# nginx backend (plain HTTP on localhost)
185169
apache::vhost { 'shorturl-backend':
186-
* => $shorturl_options,
187-
port => $ocf_www::backend_port,
188-
}
189-
190-
# canonical redirects
191-
apache::vhost { 'shorturl-http-redirect':
192-
servername => 'ocf.io',
193-
serveraliases => ['dev-ocf-io.ocf.berkeley.edu', 'www.ocf.io'],
194-
port => 80,
195-
docroot => '/var/www/html',
196-
197-
redirect_status => 'permanent',
198-
redirect_dest => $canonical_url;
170+
* => $shorturl_options,
199171
}
200172
}

modules/ocf_www/manifests/site/unavailable.pp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,7 @@
3939
],
4040
}
4141

42-
apache::vhost { 'unavailable':
43-
* => $options,
44-
port => 80,
45-
}
46-
47-
apache::vhost { 'https-unavailable':
48-
* => $options,
49-
port => 443,
50-
51-
ssl => true,
52-
ssl_key => "/etc/ssl/private/${::fqdn}.key",
53-
ssl_cert => "/etc/ssl/private/${::fqdn}.crt",
54-
ssl_chain => "/etc/ssl/private/${::fqdn}.intermediate",
55-
}
56-
57-
# nginx backend (plain HTTP on localhost)
5842
apache::vhost { 'unavailable-backend':
59-
* => $options,
60-
port => $ocf_www::backend_port,
43+
* => $options,
6144
}
6245
}

0 commit comments

Comments
 (0)