diff --git a/dockerfiles/nginx/proxito.conf b/dockerfiles/nginx/proxito.conf index 1bd2bcb9282..9320066cbd8 100644 --- a/dockerfiles/nginx/proxito.conf +++ b/dockerfiles/nginx/proxito.conf @@ -20,8 +20,12 @@ 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; + + proxy_intercept_errors on; + error_page 404 = @proxito404; add_header X-Served Django-Proxito always; } @@ -31,17 +35,29 @@ 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. + # I think the `set` must get read before doing the proxy_pass + # but the `add_header` is read after + 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 diff --git a/readthedocs/proxito/views/serve.py b/readthedocs/proxito/views/serve.py index ac3aaa11324..672030a1254 100644 --- a/readthedocs/proxito/views/serve.py +++ b/readthedocs/proxito/views/serve.py @@ -143,6 +143,7 @@ def get(self, return self._serve_docs( request, final_project=final_project, + version_slug=version_slug, path=final_url, )