Skip to content

Instantly share code, notes, and snippets.

@DarkWiiPlayer
Last active February 3, 2024 11:39
Show Gist options
  • Save DarkWiiPlayer/2a102bea866e14321b7f4ff57dc1ea17 to your computer and use it in GitHub Desktop.
Save DarkWiiPlayer/2a102bea866e14321b7f4ff57dc1ea17 to your computer and use it in GitHub Desktop.
Openresty installation script
#!/bin/bash
# This script installs OpenResty on an ubuntu-like system.
if [ "$(id -u)" -ne 0 ]
then
echo 'must run as root 😖'
exit
fi
umask a+rx
# latest='openresty-1.13.6.2'
# latest='openresty-1.15.8.2'
# latest='openresty-1.17.8.2'
# latest='openresty-1.19.9.1'
# latest='openresty-1.21.4.1'
latest='openresty-1.25.3.1'
echo 'Downloading dependancies...'
apt-get -y install libpcre3-dev libssl-dev perl make build-essential curl libzip-dev zlib1g-dev || exit 1
echo 'Downloading stuff...'
wget 'https://openresty.org/download/'$latest'.tar.gz'
echo 'Decompressing stuff...'
tar -xzf $latest'.tar.gz'
cd $latest
# Uncomment this if you want to use the tarantool module
#git clone https://github.com/tarantool/nginx_upstream_module.git tarantool_upstream --recursive
#cd tarantool_upstream
#make -j `nproc` yajl && make -j `nproc` msgpack || exit
#cd ../
./configure \
--with-pcre-jit \
--with-http_v2_module \
--with-http_ssl_module \
--with-mail \
--with-stream \
--with-threads \
--with-file-aio \
--with-http_realip_module \
--with-stream_ssl_module \
--with-stream \
--with-stream_ssl_module \
--with-stream \
--with-stream_ssl_module \
--with-http_stub_status_module \
&& make -j $(nproc) && make install || exit
# --add-module=tarantool_upstream \
cd ..
echo 'Deleting stuff...'
find -maxdepth 1 -name "$latest*" | xargs rm -rf
ln -s /usr/local/openresty/nginx/sbin/nginx /usr/local/bin
ln -s /usr/local/openresty/bin/openresty /usr/local/bin
#echo 'mkdir -p logs; exec /usr/local/openresty/bin/openresty -g "daemon off;" -p `pwd` -c openresty.conf "$@"' > /usr/local/bin/openresty || exit
#chmod a+rx /usr/local/bin/openresty
#echo 'exec /usr/local/openresty/bin/resty --nginx /usr/local/bin/openresty "$@"' > /usr/local/bin/resty || exit
#chmod a+rx /usr/local/bin/resty
cat <<'CONF' > /usr/local/openresty/example.conf || exit
# user changeme;
# Change this if you want to run openresty as root to get access to port 80
worker_processes 1; # change for production
# can also be set to `nproc` using the -g flag on the command line
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;
pid openresty.pid;
events {
worker_connections 1024;
}
http {
lua_code_cache off; # Change this for production
lua_package_path 'lua_modules/share/lua/5.1/?.lua;lua_modules/share/lua/5.1/?/init.lua;;';
lua_package_cpath 'lua_modules/lib/lua/5.1/?.so;lua_modules/lib/lua/5.1/?/init.so;;';
include /usr/local/openresty/nginx/conf/mime.types;
default_type text/html; # For user-facing webpages
# default_type application/json; # For JSON APIs
charset utf-8;
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 logs/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 8080; # Possibly change to 80 (requires root)
location /static {
deny all;
}
location ~ ^/(styles|javascript|images)/(.*) {
# Very useful, but opens the doors to nosy neighbors.
# Enable it only if you need it for scripting or something.
# autoindex on;
# autoindex_format json;
alias static/$1/$2;
}
location /favicon.png {
alias static/favicon.png;
}
location = / {
# todo: Start adding stuff here.
# Recommendation for an organized structure:
# content_by_lua_file controllers/front.lua;
# or something like that.
content_by_lua_block { ngx.say 'Hello World!' }
}
}
}
CONF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment