Changing the Nginx config to a single file
I've combined the core nginx.conf with the proxy config, which all goes into /etc/nginx/nginx.conf. I've made a number of changes: * Nginx now proxies both SQL API and Windshaft requests through Varnish. * Nginx adds a custom HTTP header, X-Carto-Service, so that Varnish can differentiate between backends (since it can't do so based on incoming port). * I've modified the primary Nginx log format to include more information on how requests are being proxied--you can now see the upstream address for proxied requests. * I've added the `proxy_no_cache` and `proxy_cache_bypass` directives to the Windshaft and SQL API proxy sections. Without those directives, Nginx may attempt to act as a cache, returning 304 Not Modified for resources that more accurately should be cached by Varnish (whose cache is invalidated via a Postgres trigger for updated metadata).
This commit is contained in:
parent
906d496494
commit
5f0eb86bed
@ -221,7 +221,7 @@ ADD ./config/app_config.yml /cartodb/config/app_config.yml
|
|||||||
ADD ./config/database.yml /cartodb/config/database.yml
|
ADD ./config/database.yml /cartodb/config/database.yml
|
||||||
ADD ./create_dev_user /cartodb/script/create_dev_user
|
ADD ./create_dev_user /cartodb/script/create_dev_user
|
||||||
ADD ./setup_organization.sh /cartodb/script/setup_organization.sh
|
ADD ./setup_organization.sh /cartodb/script/setup_organization.sh
|
||||||
ADD ./config/cartodb.nginx.proxy.conf /etc/nginx/sites-enabled/default
|
ADD ./config/cartodb.nginx.proxy.conf /etc/nginx/nginx.conf
|
||||||
ADD ./config/varnish.vcl /etc/varnish.vcl
|
ADD ./config/varnish.vcl /etc/varnish.vcl
|
||||||
ADD ./geocoder.sh /cartodb/script/geocoder.sh
|
ADD ./geocoder.sh /cartodb/script/geocoder.sh
|
||||||
ADD ./geocoder_server.sql /cartodb/script/geocoder_server.sql
|
ADD ./geocoder_server.sql /cartodb/script/geocoder_server.sql
|
||||||
|
@ -1,46 +1,80 @@
|
|||||||
server {
|
user www-data;
|
||||||
server_name cartodb.localhost *.cartodb.localhost;
|
worker_processes auto;
|
||||||
|
pid /run/nginx.pid;
|
||||||
|
include /etc/nginx/modules-enabled/*.conf;
|
||||||
|
|
||||||
client_max_body_size 0;
|
events {
|
||||||
|
worker_connections 768;
|
||||||
location ~* /(user/.*/)?api/v1/maps {
|
}
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
http {
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
sendfile on;
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
tcp_nopush on;
|
||||||
proxy_pass http://127.0.0.1:3000;
|
tcp_nodelay on;
|
||||||
}
|
keepalive_timeout 65;
|
||||||
|
types_hash_max_size 2048;
|
||||||
location ~* /(user/.*/)?api/v1/map {
|
include /etc/nginx/mime.types;
|
||||||
proxy_set_header Host $host;
|
default_type application/octet-stream;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
ssl_prefer_server_ciphers on;
|
||||||
proxy_pass http://127.0.0.1:8181;
|
|
||||||
}
|
access_log /var/log/nginx/access.log;
|
||||||
|
error_log /var/log/nginx/error.log;
|
||||||
location ~* /(user/.*)?/api/v2/sql {
|
|
||||||
# RedHog: Hack to work around bug in cartodb local hosting but using cdn for js libs
|
log_format main '[$time_local] $status REQUEST: "$request" REFERER: "$http_referer" FWD_FOR "$http_x_forwarded_for" PROXY_HOST: "$proxy_host" UPSTREAM_ADDR: "$upstream_addr"';
|
||||||
rewrite /(user/.*)?/api/v2/sql(.*) /$1/api/v2/sql$2 break;
|
|
||||||
proxy_set_header Host $host;
|
gzip on;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
server {
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
server_name cartodb.localhost *.cartodb.localhost;
|
||||||
proxy_pass http://127.0.0.1:8080;
|
client_max_body_size 0;
|
||||||
}
|
|
||||||
|
location ~* /(user/.*/)?api/v1/maps {
|
||||||
location ^~ /assets {
|
proxy_set_header Host $host;
|
||||||
root /cartodb/public;
|
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 $scheme;
|
||||||
location / {
|
proxy_pass http://127.0.0.1:3000;
|
||||||
proxy_set_header Host $host;
|
}
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
location ~* /(user/.*/)?api/v1/map {
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header Host $host;
|
||||||
proxy_pass http://127.0.0.1:3000;
|
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 $scheme;
|
||||||
error_log /var/log/nginx/cartodb_error.log;
|
proxy_set_header X-Carto-Service windshaft; # tell varnish what backend
|
||||||
access_log /var/log/nginx/cartodb_access.log;
|
proxy_no_cache true; # Make sure nginx doesn't cache
|
||||||
|
proxy_cache_bypass true; # Make sure nginx doesn't cache
|
||||||
|
proxy_pass http://127.0.0.1:6081; # hand off to Varnish
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~* /(user/.*/)?api/v2/sql {
|
||||||
|
# RedHog: Hack to work around bug in cartodb local hosting but using cdn for js libs
|
||||||
|
rewrite /(user/.*)?/api/v2/sql(.*) /$1/api/v2/sql$2 break;
|
||||||
|
proxy_set_header Host $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 $scheme;
|
||||||
|
proxy_set_header X-Carto-Service sqlapi; # tell varnish what backend
|
||||||
|
proxy_no_cache true; # make sure nginx doesn't cache
|
||||||
|
proxy_cache_bypass true; # make sure nginx doesn't cache
|
||||||
|
proxy_pass http://127.0.0.1:6081; # hand off to Varnish
|
||||||
|
}
|
||||||
|
|
||||||
|
location ^~ /assets {
|
||||||
|
root /cartodb/public;
|
||||||
|
}
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_set_header Host $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 $scheme;
|
||||||
|
proxy_pass http://127.0.0.1:3000;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_log /var/log/nginx/cartodb_error.log;
|
||||||
|
access_log /var/log/nginx/cartodb_access.log main;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user