Last active
April 26, 2020 09:15
-
-
Save linuxmalaysia/cf9cd323dad486b2197c38a0c8a107fb to your computer and use it in GitHub Desktop.
nginx for elasticsearch with username password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### http://shairosenfeld.blogspot.com/2011/03/authorization-header-in-nginx-for.html | |
### https://www.opinionatedgeek.com/codecs/base64encoder | |
### (Pilih URL safe) | |
### Example user ujian and password ujian 1234 | |
# ujian:ujian1234 | |
# Base64 for nginx | |
# dWppYW46dWppYW4xMjM0 | |
### ================ | |
server { | |
listen 8081; | |
### access_log /var/log/nginx/elasticsearch_access.log; | |
### error_log /var/log/nginx/elasticsearch_error.log error; | |
access_log off; | |
error_log /dev/null; | |
location / { | |
proxy_pass https://elasticnode1:9200; | |
proxy_http_version 1.1; | |
proxy_set_header Connection "Keep-Alive"; | |
proxy_set_header Proxy-Connection "Keep-Alive"; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $host; | |
proxy_set_header Authorization "Basic dWppYW46dWppYW4xMjM0"; | |
### https://discuss.elastic.co/t/courier-fetch-bad-gateway-6-4-0/146068/6 | |
### https://www.digitalocean.com/community/tutorials/understanding-nginx-http-proxying-load-balancing-buffering-and-caching | |
proxy_buffering off; | |
proxy_buffer_size 128k; | |
proxy_buffers 4 256k; | |
proxy_busy_buffers_size 256k; | |
} | |
} | |
#### Test it | |
# curl -X GET "localhost:8081/_cat/indices/*?v&s=index&pretty" | |
### ---- setting for nginx.conf for inject big data increase timeout | |
### https://www.digitalocean.com/community/tools/nginx | |
user nginx; | |
worker_processes auto; | |
worker_rlimit_nofile 65535; | |
error_log /var/log/nginx/error.log warn; | |
pid /var/run/nginx.pid; | |
events { | |
multi_accept on; | |
worker_connections 65535; | |
} | |
http { | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for"'; | |
access_log /var/log/nginx/access.log main; | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay on; | |
server_tokens off; | |
log_not_found off; | |
types_hash_max_size 2048; | |
client_max_body_size 16M; | |
keepalive_timeout 3000; | |
fastcgi_read_timeout 3000; | |
proxy_read_timeout 3000; | |
gzip on; | |
include /etc/nginx/conf.d/*.conf; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment