Properly proxy the Proxito headers via nginx/sendfile
This is a hack, but it works.
@@ -3,6 +3,7 @@ server {
listen 80 default_server;
server_name *.community.dev.readthedocs.io *.org.dev.readthedocs.build;
+
# TODO: serve the favicon.ico from the project/version itself instead
location /favicon.ico {
proxy_pass http://storage:10000/devstoreaccount1/static/images/favicon.ico;
@@ -20,10 +21,10 @@ server {
location / {
proxy_pass http://proxito:8000;
proxy_set_header Host $host;
- proxy_intercept_errors on;
- error_page 404 = @notfoundfallback;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Host $host;
- add_header X-Served Django-Proxito always;
}
# Sendfile support to serve the actual files that Proxito has specified
@@ -31,17 +32,27 @@ server {
internal;
# Nginx will strip the `/proxito/` and pass just the `$storage/$type/$proj/$ver/$filename`
proxy_pass http://storage:10000/;
+
proxy_set_header Host storage:10000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
-
proxy_intercept_errors on;
error_page 404 = @notfoundfallback;
- add_header X-Served Nginx-Proxito-Sendfile always;
- add_header X-RTD-Project $upstream_http_x_rtd_project always;
+ # Nginx is silly, so we have to *set* these then use them.
+ # Using them directly gets the values from the storage upstream.
+ set $rtd_project $upstream_http_x_rtd_project;
+ add_header X-RTD-Project $rtd_project always;
+ set $rtd_version $upstream_http_x_rtd_version;
+ add_header X-RTD-Version $rtd_version always;
+ set $rtd_path $upstream_http_x_rtd_path;
+ add_header X-RTD-Path $rtd_path always;
+ set $rtd_domain $upstream_http_x_rtd_domain;
+ add_header X-RTD-Domain $rtd_domain always;
+ set $rtd_method $upstream_http_x_rtd_version_method;
+ add_header X-RTD-Version-Method $rtd_method always;
}
# Serve 404 pages here
