Skip to content

Instantly share code, notes, and snippets.

@todiadiyatmo
Last active August 31, 2018 09:36
Show Gist options
  • Save todiadiyatmo/972144df77140ea8b09e to your computer and use it in GitHub Desktop.
Save todiadiyatmo/972144df77140ea8b09e to your computer and use it in GitHub Desktop.
Config Server

Nginx

user  nobody;
# no need for more workers in the proxy mode
worker_processes  4;
error_log  /var/log/nginx/error.log warn;
worker_rlimit_nofile 20480;
events {
	worker_connections 4048; # increase for busier servers
	use epoll; # you should use epoll here for Linux kernels 2.6.x
}
http {
	server_name_in_redirect off;
	server_names_hash_max_size 10240;
	server_names_hash_bucket_size 1024;
	include    mime.types;
	default_type  application/octet-stream;
	server_tokens off;
	# remove/commentout disable_symlinks if_not_owner;if you get Permission denied error
	# disable_symlinks if_not_owner;
	sendfile on;
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout  5;
	gzip on;
	gzip_vary on;
	gzip_disable "MSIE [1-6]\.";
	gzip_proxied any;
	gzip_http_version 1.0;
	gzip_min_length  1000;
	gzip_comp_level  6;
	gzip_buffers  16 8k;
	
	#CloudFlare
	set_real_ip_from 103.21.244.0/22;
	set_real_ip_from 103.22.200.0/22;
	set_real_ip_from 103.31.4.0/22;
	set_real_ip_from 104.16.0.0/12;
	set_real_ip_from 108.162.192.0/18;
	set_real_ip_from 141.101.64.0/18;
	set_real_ip_from 162.158.0.0/15;
	set_real_ip_from 172.64.0.0/13;
	set_real_ip_from 173.245.48.0/20; 
	set_real_ip_from 188.114.96.0/20;
	set_real_ip_from 190.93.240.0/20;
	set_real_ip_from 197.234.240.0/22;
	set_real_ip_from 198.41.128.0/17;
	set_real_ip_from 199.27.128.0/21;
	set_real_ip_from 2400:cb00::/32;
	set_real_ip_from 2606:4700::/32;
	set_real_ip_from 2803:f800::/32;
	set_real_ip_from 2405:b500::/32;
	set_real_ip_from 2405:8100::/32;
	real_ip_header CF-Connecting-IP;

	
	# Conection Limit
	# http://serverfault.com/questions/177461/how-to-rate-limit-in-nginx-but-including-excluding-certain-ip-addresses
	
	geo $whitelist {
	   default 0;
	   # CIDR in the list below are not limited ( 1 )
	   127.0.0.1/32 1;
           x.x.x.x/32 1; #your isp
	}
	
	map $whitelist $limit {
	    0     $binary_remote_addr;
	    1     "";
	}
	
	# The directives below limit concurrent connections from a 
	# non-whitelisted IP address to five
	 
	limit_conn_zone      $limit    zone=conlimit:30m;
	limit_conn_zone      $limit    zone=conlimit_php:30m;
	 
	limit_conn           conlimit 40;
	limit_conn_log_level warn;   # logging level when threshold exceeded
	limit_conn_status    503;    # the error code to return
	 
	# Limit Req Non - PHP 
	limit_req_zone       $limit   zone=reqlimit:30m  rate=5r/s;	
	limit_req            zone=reqlimit burst=10;
	 
	# Limit Req PHP
	limit_req_zone       $limit   zone=reqlimit_php:30m  rate=1r/s;	
	 
	limit_req_log_level  warn;
	limit_req_status     503;
		
	# You can remove image/png image/x-icon image/gif image/jpeg if you have slow CPU
	gzip_types    text/plain text/xml text/css application/x-javascript application/xml application/javascript application/xml+rss text/javascript application/atom+xml;
	ignore_invalid_headers on;
	client_header_timeout  3m;
	client_body_timeout 3m;
	send_timeout     3m;
	reset_timedout_connection on;
	connection_pool_size  256;
	client_header_buffer_size 256k;
	large_client_header_buffers 4 256k;
	client_max_body_size 200M; 
	client_body_buffer_size 128k;
	request_pool_size  32k;
	output_buffers   4 32k;
	postpone_output  1460;
	proxy_temp_path  /tmp/nginx_proxy/;
	proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:15m inactive=24h max_size=500m;
	client_body_in_file_only on;
	log_format bytes_log "$msec $bytes_sent .";
	log_format custom_microcache '$remote_addr - $remote_user [$time_local] '
	'"$request" $status $body_bytes_sent '
	'"$http_referer" "$http_user_agent" nocache:$no_cache';
	include "/etc/nginx/vhosts/*";
}

Apache

##Apache Event Default Settings (overrides main httpd.conf)
KeepAlive On
KeepAliveTimeout 1
MaxKeepAliveRequests 500
TimeOut 30
<IfModule event.c>
# Core x ThreadperChild (8-64)
ThreadsPerChild 10
ServerLimit 16
# 10 x 16 x 4mb = 640MB 
MaxRequestWorkers 160
MaxRequestsPerChild 500
StartServers 10
</IfModule>
 
<IfModule mod_fcgid.c>
    FcgidMaxRequestLen 33554432
    FcgidMinProcessesPerClass 0
    #100 MB per WP Process , must be higher than number of user in cpanel
    # number of core x 3 (VPS) n x4 (dedi)
    FcgidMaxProcesses 16
    # If you have a cpanel user > FcgidMaxProcesses, try lower this
    FcgidIdleTimeout 3
    # FcgidMaxRequestsPerProcess should be <= PHP_FCGI_MAX_REQUESTS
    #php conf /usr/local/apache/conf/php.conf 
    FcgidMaxRequestsPerProcess 500
    FcgidProcessLifeTime 900
    FcgidIdleScanInterval 0
    FcgidErrorScanInterval 0
    FcgidZombieScanInterval 0
    FcgidSpawnScoreUpLimit 7000
    FcgidSpawnScore 1
    FcgidTerminationScore -1
    FcgidTimeScore 3
    FcgidIOTimeout 30
    FcgidIdleTimeout 100
</IfModule>

MySQL

[mysqld]
max_allowed_packet=268435456
open_files_limit=10000
local-infile=0
default-storage-engine=MyISAM
innodb_file_per_table=1

max_connections = 96 # connection from php 

query_cache_type = 1
query_cache_size = 512M
query_cache_limit = 2M
#32-64mb ,2x mysqltuner recomendation
tmp_table_size = 32M
max_heap_table_size = 32M
thread_cache_size = 4
table_cache = 2000
#4 x dari table_cache
table_definition_cache = 8000
# 3 x dari table_definition_cache
# SELECT CEILING(SUM(data_length+index_length)/POWER(1024,2)) RIBPS FROM information_schema.tables WHERE engine='InnoDB';
innodb_buffer_pool_size = 512M
max_allowed_packet = 16M


innodb_log_file_size            = 5M

#log slow query

#long_query_time = 1
#log-slow-queries=/var/log/mysql/log-slow-queries.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment