Skip to content

Instantly share code, notes, and snippets.

@mafux777
Last active December 23, 2021 07:22
Show Gist options
  • Save mafux777/1db3c29441bb54d0db99c3e69f0c7624 to your computer and use it in GitHub Desktop.
Save mafux777/1db3c29441bb54d0db99c3e69f0c7624 to your computer and use it in GitHub Desktop.
Use nginx as a reverse proxy to add API key to datahub

Installation

1)

brew install nginx
sudo cp /usr/local/Cellar/nginx/1.8.0/homebrew.mxcl.nginx.plist /Library/LaunchAgents

2)

Replace /usr/local/etc/nginx/nginx.conf with the nginx.conf in this gist. I'm using port 8081 for my current project.

3)

sudo launchctl load /Library/LaunchAgents/homebrew.mxcl.nginx.plist

4)

curl -L -vv localhost:8081/status/

# Replace /usr/local/etc/nginx/nginx.conf with this. This is the
# default location for Nginx according to 'nginx -h'
worker_processes 1;
error_log /usr/local/var/log/nginx/error.log;
events {
worker_connections 1024;
}
http {
# This should be in the same directory as this conf
# e.g. /usr/local/etc/nginx
include mime.types;
default_type application/octet-stream;
# Note this log_format is named 'main', and is used with the access log below
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
keepalive_timeout 65;
# Without this I got this error: 'upstream sent too big header
# while reading response header from upstream'
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
server {
listen 8081;
server_name secret-4--rpc--full.datahub.figment.io;
access_log /usr/local/var/log/nginx/datahub.access.log main;
location / {
proxy_set_header Authorization fcc9ae7c3f5210f12d74c8cfd54adf78;
proxy_set_header Host secret-4--rpc--full.datahub.figment.io;
proxy_pass https://secret-4--rpc--full.datahub.figment.io;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment