From b549c105247e8e7003e45e4f824a887d7f011c95 Mon Sep 17 00:00:00 2001 From: gau1991 Date: Wed, 17 Dec 2014 17:25:10 +0530 Subject: [PATCH] Done Nginx configuration --- ee/cli/main.py | 4 +-- ee/cli/plugins/stack.py | 37 +++++++++++++++++++++----- ee/cli/templates/nginx-core.mustache | 39 ++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 ee/cli/templates/nginx-core.mustache diff --git a/ee/cli/main.py b/ee/cli/main.py index cd2171e4..64755ee1 100644 --- a/ee/cli/main.py +++ b/ee/cli/main.py @@ -24,8 +24,8 @@ class EEApp(foundation.CementApp): label = 'ee' # Log writing to file - #defaults = init_defaults('ee', 'log.logging') - #defaults['log.logging']['file'] = '/tmp/my.log' + # defaults = init_defaults('ee', 'log.logging') + # defaults['log.logging']['file'] = '/tmp/my.log' config_defaults = defaults diff --git a/ee/cli/plugins/stack.py b/ee/cli/plugins/stack.py index 9f0e7fa0..5deeb3ee 100644 --- a/ee/cli/plugins/stack.py +++ b/ee/cli/plugins/stack.py @@ -7,6 +7,7 @@ from ee.core.aptget import EEAptGet from ee.core.download import EEDownload from ee.core.shellexec import EEShellExec from ee.core.fileutils import EEFileUtils +from pynginxconfig import NginxConfig import random import string @@ -68,9 +69,31 @@ class EEStackController(CementBaseController): @expose(hide=True) def post_pref(self, apt_packages, packages): if len(apt_packages): + print("In post") + print(apt_packages) if "postfix" in apt_packages: pass - pass + if 'nginx-custom' in apt_packages: + # Nginx core configuration change using configparser + nc = NginxConfig() + print('in nginx') + nc.loadf('/etc/nginx/nginx.conf') + nc.set('worker_processes', 'auto') + nc.append(('worker_rlimit_nofile', '100000'), position=2) + nc.remove(('events', '')) + nc.append({'name': 'events', 'param': '', 'value': + [('worker_connections', '4096'), + ('multi_accept', 'on')]}, position=4) + nc.set([('http',), 'keepalive_timeout'], '30') + nc.savef('/etc/nginx/nginx.conf') + + # Custom Nginx configuration by EasyEngine + data = dict(version='EasyEngine 3.0.1') + ee_nginx = open('/etc/nginx/conf.d/ee-nginx.conf','w') + ee_nginx.write(self.app.render((data), 'nginx-core.mustache')) + ee_nginx.close() + + pass if len(packages): if any('/usr/bin/wp' == x[1] for x in packages): EEShellExec.cmd_exec("chmod +x /usr/bin/wp") @@ -87,10 +110,10 @@ class EEStackController(CementBaseController): EEVariables.ee_php + EEVariables.ee_mysql) if self.app.pargs.admin: pass - #apt_packages = apt_packages + EEVariables.ee_nginx + # apt_packages = apt_packages + EEVariables.ee_nginx if self.app.pargs.mail: pass - #apt_packages = apt_packages + EEVariables.ee_nginx + # apt_packages = apt_packages + EEVariables.ee_nginx if self.app.pargs.nginx: apt_packages = apt_packages + EEVariables.ee_nginx if self.app.pargs.php: @@ -122,10 +145,10 @@ class EEStackController(CementBaseController): EEVariables.ee_php + EEVariables.ee_mysql) if self.app.pargs.admin: pass - #apt_packages = apt_packages + EEVariables.ee_nginx + # apt_packages = apt_packages + EEVariables.ee_nginx if self.app.pargs.mail: pass - #apt_packages = apt_packages + EEVariables.ee_nginx + # apt_packages = apt_packages + EEVariables.ee_nginx if self.app.pargs.nginx: apt_packages = apt_packages + EEVariables.ee_nginx if self.app.pargs.php: @@ -153,10 +176,10 @@ class EEStackController(CementBaseController): + EEVariables.ee_php + EEVariables.ee_mysql) if self.app.pargs.admin: pass - #apt_packages = apt_packages + EEVariables.ee_nginx + # apt_packages = apt_packages + EEVariables.ee_nginx if self.app.pargs.mail: pass - #apt_packages = apt_packages + EEVariables.ee_nginx + # apt_packages = apt_packages + EEVariables.ee_nginx if self.app.pargs.nginx: apt_packages = apt_packages + EEVariables.ee_nginx if self.app.pargs.php: diff --git a/ee/cli/templates/nginx-core.mustache b/ee/cli/templates/nginx-core.mustache new file mode 100644 index 00000000..a3442847 --- /dev/null +++ b/ee/cli/templates/nginx-core.mustache @@ -0,0 +1,39 @@ +## +# EasyEngine Settings +## + +server_tokens off; +reset_timedout_connection on; +add_header X-Powered-By "{{version}}"; +add_header rt-Fastcgi-Cache $upstream_cache_status; + +# Limit Request +limit_req_status 403; +limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s; + +# Proxy Settings +# set_real_ip_from proxy-server-ip; +# real_ip_header X-Forwarded-For; + +fastcgi_read_timeout 300; +client_max_body_size 100m; + +# SSL Settings +ssl_session_cache shared:SSL:20m; +ssl_session_timeout 10m; +ssl_prefer_server_ciphers on; +ssl_ciphers HIGH:!aNULL:!MD5:!kEDH; + +# Log format Settings +log_format rt_cache '$remote_addr $upstream_response_time $upstream_cache_status [$time_local] ' +'$http_host "$request" $status $body_bytes_sent ' +'"$http_referer" "$http_user_agent"'; + + +# GZip settings +gzip_vary on; +gzip_proxied any; +gzip_comp_level 6; +gzip_buffers 16 8k; +gzip_http_version 1.1; +gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;