Skip to content

A platform for community discussion. Free, open, simple.

DEV: Reapply refactor of Nginx config file (#30385)

Michael Brown5bab18e3eacb
diff --git a/config/nginx.sample.conf b/config/nginx.sample.conf
index cda41bb3a9e..6bedc25a154 100644
--- a/config/nginx.sample.conf
+++ b/config/nginx.sample.conf
@@ -92,28 +92,24 @@ server {
# auth_basic on;
# auth_basic_user_file /etc/nginx/htpasswd;
+ # proxy_set_header directives are inherited from the previous configuration
+ # level if and only if there are no proxy_set_header directives defined on
+ # the current level.
+ proxy_set_header Host $http_host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Request-Start "t=${msec}";
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $thescheme;
+ proxy_set_header X-Sendfile-Type "";
+ proxy_set_header X-Accel-Mapping "";
+ proxy_set_header Client-Ip "";
+
location ~ ^/uploads/short-url/ {
- proxy_set_header Host $http_host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Request-Start "t=${msec}";
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header X-Forwarded-Proto $thescheme;
- proxy_set_header X-Sendfile-Type "";
- proxy_set_header X-Accel-Mapping "";
- proxy_set_header Client-Ip "";
proxy_pass http://discourse;
break;
}
location ~ ^/(secure-media-uploads/|secure-uploads)/ {
- proxy_set_header Host $http_host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Request-Start "t=${msec}";
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header X-Forwarded-Proto $thescheme;
- proxy_set_header X-Sendfile-Type "";
- proxy_set_header X-Accel-Mapping "";
- proxy_set_header Client-Ip "";
proxy_pass http://discourse;
break;
}
@@ -127,14 +123,6 @@ server {
location = /srv/status {
access_log off;
log_not_found off;
- proxy_set_header Host $http_host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Request-Start "t=${msec}";
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header X-Forwarded-Proto $thescheme;
- proxy_set_header X-Sendfile-Type "";
- proxy_set_header X-Accel-Mapping "";
- proxy_set_header Client-Ip "";
proxy_pass http://discourse;
break;
}
@@ -172,11 +160,9 @@ server {
}
location ~ ^/uploads/ {
- # NOTE: it is really annoying that we can't just define headers
- # at the top level and inherit.
- #
- # proxy_set_header DOES NOT inherit, by design, we must repeat it,
- # otherwise headers are not set correctly
+ # proxy_set_header directives are inherited from the previous configuration
+ # level if and only if there are no proxy_set_header directives defined on
+ # the current level.
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Request-Start "t=${msec}";
@@ -184,6 +170,8 @@ server {
proxy_set_header X-Forwarded-Proto $thescheme;
proxy_set_header X-Sendfile-Type X-Accel-Redirect;
proxy_set_header X-Accel-Mapping $public/=/downloads/;
+ proxy_set_header Client-Ip "";
+
expires 1y;
add_header Cache-Control public,immutable;
@@ -218,6 +206,9 @@ server {
}
location ~ ^/admin/backups/ {
+ # proxy_set_header directives are inherited from the previous configuration
+ # level if and only if there are no proxy_set_header directives defined on
+ # the current level.
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Request-Start "t=${msec}";
@@ -225,6 +216,8 @@ server {
proxy_set_header X-Forwarded-Proto $thescheme;
proxy_set_header X-Sendfile-Type X-Accel-Redirect;
proxy_set_header X-Accel-Mapping $public/=/downloads/;
+ proxy_set_header Client-Ip "";
+
proxy_pass http://discourse;
break;
}
@@ -233,15 +226,6 @@ server {
# acceleration for backups, avatars, sprites and so on.
# see note about repetition above
location ~ ^/(svg-sprite/|letter_avatar/|letter_avatar_proxy/|user_avatar|highlight-js|stylesheets|theme-javascripts|favicon/proxied|service-worker|extra-locales/) {
- proxy_set_header Host $http_host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Request-Start "t=${msec}";
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header X-Forwarded-Proto $thescheme;
- proxy_set_header X-Sendfile-Type "";
- proxy_set_header X-Accel-Mapping "";
- proxy_set_header Client-Ip "";
-
# if Set-Cookie is in the response nothing gets cached
# this is double bad cause we are not passing last modified in
proxy_ignore_headers "Set-Cookie";
@@ -260,14 +244,6 @@ server {
# we need buffering off for message bus
location /message-bus/ {
- proxy_set_header X-Request-Start "t=${msec}";
- proxy_set_header Host $http_host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header X-Forwarded-Proto $thescheme;
- proxy_set_header X-Sendfile-Type "";
- proxy_set_header X-Accel-Mapping "";
- proxy_set_header Client-Ip "";
proxy_http_version 1.1;
proxy_buffering off;
proxy_pass http://discourse;
@@ -284,11 +260,14 @@ server {
}
location @discourse {
+ # fallback to discourse
include conf.d/outlets/discourse/*.conf;
+ # repeat the default proxy_set_header lines from above because we didn't
+ # get here via a proxy_pass statement
proxy_set_header Host $http_host;
- proxy_set_header X-Request-Start "t=${msec}";
proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Request-Start "t=${msec}";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $thescheme;
proxy_set_header X-Sendfile-Type "";
@@ -297,3 +276,4 @@ server {
proxy_pass http://discourse;
}
}
+