Skip to content

Commit

Permalink
Merge pull request #6782 from readthedocs/fix-proxito-headers
Browse files Browse the repository at this point in the history
Properly proxy the Proxito headers via nginx/sendfile
  • Loading branch information
ericholscher authored Mar 14, 2020
2 parents 2091b2d + dc4c8f7 commit bbd844e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
26 changes: 21 additions & 5 deletions dockerfiles/nginx/proxito.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions readthedocs/proxito/views/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def get(self,
return self._serve_docs(
request,
final_project=final_project,
version_slug=version_slug,
path=final_url,
)

Expand Down

0 comments on commit bbd844e

Please sign in to comment.