Last active
March 12, 2016 05:58
-
-
Save fratuz610/fda139019dd327857d9a to your computer and use it in GitHub Desktop.
openresty config and test files - see http://bitsandpieces.it/nginx-by-examples-openresty
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
local _M = {} | |
function _M.content() { | |
ngx.say(cjson.encode({from = "a", file = "now"})) | |
} | |
return _M; |
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
#!/bin/sh | |
# | |
# chkconfig: 2345 55 25 | |
# Description: Nginx init.d script, put in /etc/init.d, chmod +x /etc/init.d/nginx | |
# For Debian, run: update-rc.d -f nginx defaults | |
# For CentOS, run: chkconfig --add nginx | |
# | |
### BEGIN INIT INFO | |
# Provides: nginx | |
# Required-Start: $all | |
# Required-Stop: $all | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: nginx init.d script | |
# Description: OpenResty (aka. ngx_openresty) is a full-fledged web application server by bundling the standard Nginx core, lots of 3rd-party Nginx modules, as well as most of their external dependencies. | |
### END INIT INFO | |
# | |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
DESC="Nginx Daemon" | |
NAME=nginx | |
PREFIX=/usr/local/openresty/nginx | |
DAEMON=$PREFIX/sbin/$NAME | |
CONF=$PREFIX/conf/$NAME.conf | |
PID=/run/$NAME.pid | |
SCRIPT=/etc/init.d/$NAME | |
if [ ! -x "$DAEMON" ] || [ ! -f "$CONF" ]; then | |
echo -e "\033[33m $DAEMON has no permission to run. \033[0m" | |
echo -e "\033[33m Or $CONF doesn't exist. \033[0m" | |
sleep 1 | |
exit 1 | |
fi | |
do_start() { | |
if [ -f $PID ]; then | |
echo -e "\033[33m $PID already exists. \033[0m" | |
echo -e "\033[33m $DESC is already running or crashed. \033[0m" | |
echo -e "\033[32m $DESC Reopening $CONF ... \033[0m" | |
$DAEMON -s reopen -c $CONF | |
sleep 1 | |
echo -e "\033[36m $DESC reopened. \033[0m" | |
else | |
echo -e "\033[32m $DESC Starting $CONF ... \033[0m" | |
$DAEMON -c $CONF | |
sleep 1 | |
echo -e "\033[36m $DESC started. \033[0m" | |
fi | |
} | |
do_stop() { | |
if [ ! -f $PID ]; then | |
echo -e "\033[33m $PID doesn't exist. \033[0m" | |
echo -e "\033[33m $DESC isn't running. \033[0m" | |
else | |
echo -e "\033[32m $DESC Stopping $CONF ... \033[0m" | |
$DAEMON -s stop -c $CONF | |
sleep 1 | |
echo -e "\033[36m $DESC stopped. \033[0m" | |
fi | |
} | |
do_reload() { | |
if [ ! -f $PID ]; then | |
echo -e "\033[33m $PID doesn't exist. \033[0m" | |
echo -e "\033[33m $DESC isn't running. \033[0m" | |
echo -e "\033[32m $DESC Starting $CONF ... \033[0m" | |
$DAEMON -c $CONF | |
sleep 1 | |
echo -e "\033[36m $DESC started. \033[0m" | |
else | |
echo -e "\033[32m $DESC Reloading $CONF ... \033[0m" | |
$DAEMON -s reload -c $CONF | |
sleep 1 | |
echo -e "\033[36m $DESC reloaded. \033[0m" | |
fi | |
} | |
do_quit() { | |
if [ ! -f $PID ]; then | |
echo -e "\033[33m $PID doesn't exist. \033[0m" | |
echo -e "\033[33m $DESC isn't running. \033[0m" | |
else | |
echo -e "\033[32m $DESC Quitting $CONF ... \033[0m" | |
$DAEMON -s quit -c $CONF | |
sleep 1 | |
echo -e "\033[36m $DESC quitted. \033[0m" | |
fi | |
} | |
do_test() { | |
echo -e "\033[32m $DESC Testing $CONF ... \033[0m" | |
$DAEMON -t -c $CONF | |
} | |
do_info() { | |
$DAEMON -V | |
} | |
case "$1" in | |
start) | |
do_start | |
;; | |
stop) | |
do_stop | |
;; | |
reload) | |
do_reload | |
;; | |
restart) | |
do_stop | |
do_start | |
;; | |
quit) | |
do_quit | |
;; | |
test) | |
do_test | |
;; | |
info) | |
do_info | |
;; | |
*) | |
echo "Usage: $SCRIPT {start|stop|reload|restart|quit|test|info}" | |
exit 2 | |
;; | |
esac | |
exit 0 |
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
user www-data; | |
worker_processes 1; | |
pid /run/nginx.pid; | |
events { | |
worker_connections 1024; | |
# multi_accept on; | |
} | |
http { | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay on; | |
keepalive_timeout 65; | |
types_hash_max_size 2048; | |
server_tokens off; | |
# server_names_hash_bucket_size 64; | |
# server_name_in_redirect off; | |
include mime.types; | |
default_type application/octet-stream; | |
# Logging Settings | |
access_log /usr/local/openresty/nginx/logs/access.log; | |
error_log /usr/local/openresty/nginx/logs/error.log; | |
# Gzip Settings | |
gzip off; | |
gzip_disable "msie6"; | |
# 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; | |
# we accept post requests with a body up to 128mb | |
client_max_body_size 128m; | |
# we set the package path to /usr/local/openresty/scripts | |
lua_package_path ";;$prefix/scripts/?.lua"; | |
# Lua initalization routine (we define a global object) | |
init_by_lua_block { | |
cjson = require "cjson" | |
} | |
# vhosts | |
server { | |
listen 80 default; | |
access_log /usr/local/openresty/nginx/logs/default.log; | |
error_log /usr/local/openresty/nginx/logs/default.log; | |
# for development only | |
lua_code_cache off; | |
# In production use | |
#lua_code_cache on; | |
location / { | |
default_type text/html; | |
content_by_lua_block { | |
ngx.say(cjson.encode({dog = 5, cat = 6})) | |
} | |
} | |
location /lua-file { | |
default_type text/html; | |
content_by_lua_block { | |
require('lua-file').content() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment