on master help sign in
nginx: normalize installation (docs and script)s over all distros

This is the revision of the documentation about the varous nginx installation variants. It also implements the nginx installation scripts for morty and filtron. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>

commit58d5da8b57c5aeab92f551e8d175be67537c351c authorMarkus Heiser <markus.heiser@darmarit.de> dateSat 11 Apr 2020, 13:19 (7 years ago) parent67afa6b
9 files changed+414−80
docs/admin/filtron.rst+16−1 docs/admin/installation-nginx.rst+60−42 utils/filtron.sh+59−7 utils/lib.sh+180−5 utils/lxc.sh+9−11 utils/morty.sh+61−8 utils/searx.sh+2−6 utils/templates/etc/nginx/default.apps-available/morty.conf+11 utils/templates/etc/nginx/default.apps-available/searx.conf:filtron+16
docs/admin/filtron.rst+16−1
@@ -158,6 +158,12 @@ of:
158158Route request through filtron
159159=============================
160160
161+.. sidebar:: further reading
162+
163+ - :ref:`filtron.sh overview`
164+ - :ref:`installation nginx`
165+ - :ref:`installation apache`
166+
161167Filtron can be started using the following command:
162168
163169.. code:: sh
@@ -171,15 +177,24 @@ Use it along with ``nginx`` with the following example configuration.
171177
172178.. code:: nginx
173179
174− location / {
180+ # https://example.org/searx
181+
182+ location /searx {
175183 proxy_pass http://127.0.0.1:4004/;
176184
177185 proxy_set_header Host $http_host;
186+ proxy_set_header Connection $http_connection;
178187 proxy_set_header X-Real-IP $remote_addr;
179188 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
180189 proxy_set_header X-Scheme $scheme;
190+ proxy_set_header X-Script-Name /searx;
181191 }
182192
193+ location /searx/static {
194+ /usr/local/searx/searx-src/searx/static;
195+ }
196+
197+
183198Requests are coming from port 4004 going through filtron and then forwarded to
184199port 8888 where a searx is being run. For a complete setup see: :ref:`nginx
185200searx site`.
docs/admin/installation-nginx.rst+60−42
@@ -159,14 +159,22 @@ Started wiki`_ is always a good resource *to keep in the pocket*.
159159
160160 .. code:: nginx
161161
162− location / {
163− proxy_pass http://127.0.0.1:4004/;
162+ # https://example.org/searx
164163
165− proxy_set_header Host $http_host;
166− proxy_set_header X-Real-IP $remote_addr;
167− proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
168− proxy_set_header X-Scheme $scheme;
169− }
164+ location /searx {
165+ proxy_pass http://127.0.0.1:4004/;
166+
167+ proxy_set_header Host $http_host;
168+ proxy_set_header Connection $http_connection;
169+ proxy_set_header X-Real-IP $remote_addr;
170+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
171+ proxy_set_header X-Scheme $scheme;
172+ proxy_set_header X-Script-Name /searx;
173+ }
174+
175+ location /searx/static {
176+ /usr/local/searx/searx-src/searx/static;
177+ }
170178
171179
172180 2. Configure reverse proxy for :ref:`morty <searx morty>`, listening on
@@ -174,10 +182,13 @@ Started wiki`_ is always a good resource *to keep in the pocket*.
174182
175183 .. code:: nginx
176184
177− location /morty {
185+ # https://example.org/morty
186+
187+ location /morty {
178188 proxy_pass http://127.0.0.1:3000/;
179189
180190 proxy_set_header Host $http_host;
191+ proxy_set_header Connection $http_connection;
181192 proxy_set_header X-Real-IP $remote_addr;
182193 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
183194 proxy_set_header X-Scheme $scheme;
@@ -197,7 +208,7 @@ Started wiki`_ is always a good resource *to keep in the pocket*.
197208 image_proxy : True
198209
199210
200− .. group-tab:: proxy or uWSGI
211+ .. group-tab:: proxy or uWSGI
201212
202213 Be warned, with this setup, your instance isn't :ref:`protected <searx
203214 filtron>`. Nevertheless it is good enough for intranet usage and it is a
@@ -208,15 +219,17 @@ Started wiki`_ is always a good resource *to keep in the pocket*.
208219
209220 .. code:: nginx
210221
211− location / {
212− proxy_pass http://127.0.0.1:8888;
222+ # https://hostname.local/
213223
214− proxy_set_header Host $host;
215− proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
216− proxy_set_header X-Scheme $scheme;
217− proxy_set_header X-Script-Name /searx;
218− proxy_buffering off;
219− }
224+ location / {
225+ proxy_pass http://127.0.0.1:8888;
226+
227+ proxy_set_header Host $host;
228+ proxy_set_header Connection $http_connection;
229+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
230+ proxy_set_header X-Scheme $scheme;
231+ proxy_buffering off;
232+ }
220233
221234 Alternatively you can use the `uWSGI support from nginx`_ via unix
222235 sockets. For socket communication, you have to activate ``socket =
@@ -234,8 +247,8 @@ Started wiki`_ is always a good resource *to keep in the pocket*.
234247 .. code:: nginx
235248
236249 server {
237− # replace example.org with your server's public name
238− server_name example.org;
250+ # replace hostname.local with your server's name
251+ server_name hostname.local;
239252
240253 listen 80;
241254 listen [::]:80;
@@ -245,7 +258,7 @@ Started wiki`_ is always a good resource *to keep in the pocket*.
245258 uwsgi_pass unix:/run/uwsgi/app/searx/socket;
246259 }
247260
248− root /usr/local/searx/searx-src/searx;
261+ root /usr/local/searx/searx-src/searx;
249262 location /static { }
250263 }
251264
@@ -254,10 +267,10 @@ Started wiki`_ is always a good resource *to keep in the pocket*.
254267
255268 .. code:: bash
256269
257− mkdir -p /run/uwsgi/app/searx/
258− sudo -H chown -R searx:searx /run/uwsgi/app/searx/
270+ mkdir -p /run/uwsgi/app/searx/
271+ sudo -H chown -R searx:searx /run/uwsgi/app/searx/
259272
260− .. group-tab:: proxy at subdir URL
273+ .. group-tab:: \.\. at subdir URL
261274
262275 Be warned, with these setups, your instance isn't :ref:`protected <searx
263276 filtron>`. The examples are just here to demonstrate how to export the
@@ -265,19 +278,22 @@ Started wiki`_ is always a good resource *to keep in the pocket*.
265278
266279 .. code:: nginx
267280
268− location /searx {
269− proxy_pass http://127.0.0.1:8888;
281+ # https://hostname.local/searx
270282
271− proxy_set_header Host $host;
272− proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
273− proxy_set_header X-Scheme $scheme;
274− proxy_set_header X-Script-Name /searx;
275− proxy_buffering off;
276− }
283+ location /searx {
284+ proxy_pass http://127.0.0.1:8888;
285+
286+ proxy_set_header Host $host;
287+ proxy_set_header Connection $http_connection;
288+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
289+ proxy_set_header X-Scheme $scheme;
290+ proxy_set_header X-Script-Name /searx;
291+ proxy_buffering off;
292+ }
277293
278− location /searx/static {
279− alias /usr/local/searx/searx-src/searx/static;
280− }
294+ location /searx/static {
295+ alias /usr/local/searx/searx-src/searx/static;
296+ }
281297
282298 The ``X-Script-Name /searx`` is needed by the searx implementation to
283299 calculate relative URLs correct. The next example shows a uWSGI
@@ -286,15 +302,17 @@ Started wiki`_ is always a good resource *to keep in the pocket*.
286302
287303 .. code:: nginx
288304
289− location /searx/static {
290− alias /usr/local/searx/searx-src/searx;
291− }
305+ # https://hostname.local/searx
306+
307+ location /searx {
308+ uwsgi_param SCRIPT_NAME /searx;
309+ include uwsgi_params;
310+ uwsgi_pass unix:/run/uwsgi/app/searx/socket;
311+ }
292312
293− location /searx {
294− uwsgi_param SCRIPT_NAME /searx;
295− include uwsgi_params;
296− uwsgi_pass unix:/run/uwsgi/app/searx/socket;
297− }
313+ location /searx/static {
314+ alias /usr/local/searx/searx-src/searx;
315+ }
298316
299317 For searx to work correctly the ``base_url`` must be set in the
300318 :origin:`searx/settings.yml`.
utils/filtron.sh+59−7
@@ -44,9 +44,8 @@ GO_ENV="${SERVICE_HOME}/.go_env"
4444GO_PKG_URL="https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz"
4545GO_TAR=$(basename "$GO_PKG_URL")
4646
47−# Apache Settings
48−
4947APACHE_FILTRON_SITE="searx.conf"
48+NGINX_FILTRON_SITE="searx.conf"
5049
5150# shellcheck disable=SC2034
5251CONFIG_FILES=(
@@ -60,9 +59,7 @@ usage() {
6059
6160 # shellcheck disable=SC1117
6261 cat <<EOF
63−
6462usage::
65−
6663 $(basename "$0") shell
6764 $(basename "$0") install [all|user|rules]
6865 $(basename "$0") update [filtron]
@@ -72,6 +69,7 @@ usage::
7269 $(basename "$0") inspect [service]
7370 $(basename "$0") option [debug-on|debug-off]
7471 $(basename "$0") apache [install|remove]
72+ $(basename "$0") nginx [install|remove]
7573
7674shell
7775 start interactive shell from user ${SERVICE_USER}
@@ -92,6 +90,9 @@ option
9290apache (${PUBLIC_URL})
9391 :install: apache site with a reverse proxy (ProxyPass)
9492 :remove: apache site ${APACHE_FILTRON_SITE}
93+nginx (${PUBLIC_URL})
94+ :install: nginx site with a reverse proxy (ProxyPass)
95+ :remove: nginx site ${NGINX_FILTRON_SITE}
9596
9697filtron rules: ${FILTRON_RULES}
9798
@@ -118,8 +119,6 @@ EOF
118119}
119120
120121main() {
121− rst_title "$SERVICE_NAME" part
122−
123122 required_commands \
124123 sudo install git wget curl \
125124 || exit
@@ -127,7 +126,7 @@ main() {
127126 local _usage="unknown or missing $1 command $2"
128127
129128 case $1 in
130− --source-only) ;;
129+ --getenv) var="$2"; echo "${!var}"; exit 0;;
131130 -h|--help) usage; exit 0;;
132131
133132 shell)
@@ -143,6 +142,7 @@ main() {
143142 *) usage "$_usage"; exit 42;;
144143 esac ;;
145144 install)
145+ rst_title "$SERVICE_NAME" part
146146 sudo_or_exit
147147 case $2 in
148148 all) install_all ;;
@@ -187,6 +187,13 @@ main() {
187187 remove) remove_apache_site ;;
188188 *) usage "$_usage"; exit 42;;
189189 esac ;;
190+ nginx)
191+ sudo_or_exit
192+ case $2 in
193+ install) install_nginx_site ;;
194+ remove) remove_nginx_site ;;
195+ *) usage "$_usage"; exit 42;;
196+ esac ;;
190197 option)
191198 sudo_or_exit
192199 case $2 in
@@ -473,6 +480,51 @@ This removes apache site ${APACHE_FILTRON_SITE}."
473480
474481}
475482
483+install_nginx_site() {
484+
485+ rst_title "Install nginx site $NGINX_FILTRON_SITE"
486+
487+ rst_para "\
488+This installs a reverse proxy (ProxyPass) into nginx site (${NGINX_FILTRON_SITE})"
489+
490+ ! nginx_is_installed && err_msg "nginx is not installed."
491+
492+ if ! ask_yn "Do you really want to continue?" Yn; then
493+ return
494+ else
495+ install_nginx
496+ fi
497+
498+ "${REPO_ROOT}/utils/searx.sh" install uwsgi
499+
500+ SEARX_SRC=$("${REPO_ROOT}/utils/searx.sh" --getenv SEARX_SRC)
501+ SEARX_URL_PATH=$("${REPO_ROOT}/utils/searx.sh" --getenv SEARX_URL_PATH)
502+ nginx_install_app --variant=filtron "${NGINX_FILTRON_SITE}"
503+
504+ info_msg "testing public url .."
505+ if ! service_is_available "${PUBLIC_URL}"; then
506+ err_msg "Public service at ${PUBLIC_URL} is not available!"
507+ fi
508+}
509+
510+remove_nginx_site() {
511+
512+ rst_title "Remove nginx site $NGINX_FILTRON_SITE"
513+
514+ rst_para "\
515+This removes nginx site ${NGINX_FILTRON_SITE}."
516+
517+ ! nginx_is_installed && err_msg "nginx is not installed."
518+
519+ if ! ask_yn "Do you really want to continue?" Yn; then
520+ return
521+ fi
522+
523+ nginx_remove_site "$FILTRON_FILTRON_SITE"
524+
525+}
526+
527+
476528rst-doc() {
477529
478530 eval "echo \"$(< "${REPO_ROOT}/docs/build-templates/filtron.rst")\""
utils/lib.sh+180−5
@@ -138,6 +138,16 @@ rst_para() {
138138 fi
139139}
140140
141+die() {
142+ echo -e "${_BRed}ERROR:${_creset} ${BASH_SOURCE[1]}: line ${BASH_LINENO[0]}: ${2-died ${1-1}}" >&2;
143+ exit "${1-1}"
144+}
145+
146+die_caller() {
147+ echo -e "${_BRed}ERROR:${_creset} ${BASH_SOURCE[2]}: line ${BASH_LINENO[1]}: ${FUNCNAME[1]}(): ${2-died ${1-1}}" >&2;
148+ exit "${1-1}"
149+}
150+
141151err_msg() { echo -e "${_BRed}ERROR:${_creset} $*" >&2; }
142152warn_msg() { echo -e "${_BBlue}WARN:${_creset} $*" >&2; }
143153info_msg() { echo -e "${_BYellow}INFO:${_creset} $*" >&2; }
@@ -471,11 +481,7 @@ service_is_available() {
471481
472482 # usage: service_is_available <URL>
473483
474− local URL="$1"
475− if [[ -z $URL ]]; then
476− err_msg "service_is_available: missing arguments"
477− return 42
478− fi
484+ [[ -z $1 ]] && die_caller 42 "missing argument <URL>"
479485
480486 http_code=$(curl -H 'Cache-Control: no-cache' \
481487 --silent -o /dev/null --head --write-out '%{http_code}' --insecure \
@@ -624,6 +630,175 @@ EOF
624630}
625631
626632
633+# nginx
634+# -----
635+
636+nginx_distro_setup() {
637+ # shellcheck disable=SC2034
638+
639+ NGINX_DEFAULT_SERVER=/etc/nginx/nginx.conf
640+
641+ # Including *location* directives from a dedicated config-folder into the
642+ # server directive is, what what fedora (already) does.
643+ NGINX_APPS_ENABLED="/etc/nginx/default.d"
644+
645+ # We add a apps-available folder and linking configurations into the
646+ # NGINX_APPS_ENABLED folder. See also nginx_include_apps_enabled().
647+ NGINX_APPS_AVAILABLE="/etc/nginx/default.apps-available"
648+
649+ case $DIST_ID-$DIST_VERS in
650+ ubuntu-*|debian-*)
651+ NGINX_PACKAGES="nginx"
652+ NGINX_DEFAULT_SERVER=/etc/nginx/sites-available/default
653+ ;;
654+ arch-*)
655+ NGINX_PACKAGES="nginx-mainline"
656+ ;;
657+ fedora-*)
658+ NGINX_PACKAGES="nginx"
659+ ;;
660+ *)
661+ err_msg "$DIST_ID-$DIST_VERS: nginx not yet implemented"
662+ ;;
663+ esac
664+}
665+nginx_distro_setup
666+
667+install_nginx(){
668+ info_msg "installing nginx ..."
669+ pkg_install "${NGINX_PACKAGES}"
670+ case $DIST_ID-$DIST_VERS in
671+ arch-*|fedora-*)
672+ systemctl enable nginx
673+ systemctl start nginx
674+ ;;
675+ esac
676+}
677+
678+nginx_is_installed() {
679+ command -v nginx &>/dev/null
680+}
681+
682+nginx_reload() {
683+
684+ info_msg "reload nginx .."
685+ echo
686+ if ! nginx -t; then
687+ err_msg "testing nginx configuration failed"
688+ return 42
689+ fi
690+ systemctl restart nginx
691+}
692+
693+nginx_install_app() {
694+
695+ # usage: nginx_install_app [<template option> ...] <myapp>
696+ #
697+ # <template option>: see install_template
698+
699+ local template_opts=()
700+ local pos_args=("$0")
701+
702+ for i in "$@"; do
703+ case $i in
704+ -*) template_opts+=("$i");;
705+ *) pos_args+=("$i");;
706+ esac
707+ done
708+
709+ nginx_include_apps_enabled "${NGINX_DEFAULT_SERVER}"
710+
711+ install_template "${template_opts[@]}" \
712+ "${NGINX_APPS_AVAILABLE}/${pos_args[1]}" \
713+ root root 644
714+ nginx_enable_app "${pos_args[1]}"
715+ info_msg "installed nginx app: ${pos_args[1]}"
716+}
717+
718+nginx_include_apps_enabled() {
719+
720+ # Add the *NGINX_APPS_ENABLED* infrastruture to a nginx server block. Such
721+ # infrastruture is already known from fedora, including apps (location
722+ # directives) from the /etc/nginx/default.d folder into the *default* nginx
723+ # server.
724+
725+ # usage: nginx_include_apps_enabled <config-file>
726+ #
727+ # config-file: Config file with server directive in.
728+
729+ [[ -z $1 ]] && die_caller 42 "missing argument <config-file>"
730+ local server_conf="$1"
731+
732+ # include /etc/nginx/default.d/*.conf;
733+ local include_directive="include ${NGINX_APPS_ENABLED}/*.conf;"
734+ local include_directive_re="^\s*include ${NGINX_APPS_ENABLED}/\*\.conf;"
735+
736+ info_msg "checking existence: '${include_directive}' in file ${server_conf}"
737+ if grep "${include_directive_re}" "${server_conf}"; then
738+ info_msg "OK, already exists."
739+ return
740+ fi
741+
742+ info_msg "add missing directive: '${include_directive}'"
743+ cp "${server_conf}" "${server_conf}.bak"
744+
745+ (
746+ local line
747+ local stage=0
748+ while IFS= read -r line
749+ do
750+ echo "$line"
751+ if [[ $stage = 0 ]]; then
752+ if [[ $line =~ ^[[:space:]]*server*[[:space:]]*\{ ]]; then
753+ stage=1
754+ fi
755+ fi
756+
757+ if [[ $stage = 1 ]]; then
758+ echo " # Load configuration files for the default server block."
759+ echo " $include_directive"
760+ echo ""
761+ stage=2
762+ fi
763+ done < "${server_conf}.bak"
764+ ) > "${server_conf}"
765+
766+}
767+
768+nginx_remove_app() {
769+
770+ # usage: nginx_remove_app <myapp.conf>
771+
772+ info_msg "remove nginx app: $1"
773+ nginx_dissable_app "$1"
774+ rm -f "${NGINX_APPS_AVAILABLE}/$1"
775+}
776+
777+nginx_enable_app() {
778+
779+ # usage: nginx_enable_app <myapp.conf>
780+
781+ local CONF="$1"
782+
783+ info_msg "enable nginx app: ${CONF}"
784+ mkdir -p "${NGINX_APPS_ENABLED}"
785+ rm -f "${NGINX_APPS_ENABLED}/${CONF}"
786+ ln -s "${NGINX_APPS_AVAILABLE}/${CONF}" "${NGINX_APPS_ENABLED}/${CONF}"
787+ nginx_reload
788+}
789+
790+nginx_dissable_app() {
791+
792+ # usage: nginx_disable_app <myapp.conf>
793+
794+ local CONF="$1"
795+
796+ info_msg "disable nginx app: ${CONF}"
797+ rm -f "${NGINX_APPS_ENABLED}/${CONF}"
798+ nginx_reload
799+}
800+
801+
627802# Apache
628803# ------
629804
utils/lxc.sh+9−11
@@ -73,9 +73,7 @@ usage() {
7373# ----------------------------------------------------------------------------
7474 _cmd="$(basename "$0")"
7575 cat <<EOF
76−
7776usage::
78−
7977 $_cmd build [containers|<name>]
8078 $_cmd copy [images]
8179 $_cmd remove [containers|<name>|images]
@@ -101,7 +99,7 @@ show
10199 :suite: show services of all (or <name>) containers from the LXC suite
102100 :images: show information of local images
103101cmd
104− use single qoutes to evaluate in container's bash, e.g. 'echo $(hostname)'
102+ use single qoutes to evaluate in container's bash, e.g.: 'echo \$(hostname)'
105103 -- run command '...' in all containers of the LXC suite
106104 :<name>: run command '...' in container <name>
107105install
@@ -151,14 +149,14 @@ main() {
151149 fi
152150
153151 case $1 in
154− --source-only) ;;
152+ --getenv) var="$2"; echo "${!var}"; exit 0;;
155153 -h|--help) usage; exit 0;;
156154
157155 build)
158156 sudo_or_exit
159157 case $2 in
160158 ${LXC_HOST_PREFIX}-*) build_container "$2" ;;
161− ''|containers) build_all_containers ;;
159+ ''|--|containers) build_all_containers ;;
162160 *) usage "$_usage"; exit 42;;
163161 esac
164162 ;;
@@ -171,7 +169,7 @@ main() {
171169 remove)
172170 sudo_or_exit
173171 case $2 in
174− ''|containers) remove_containers ;;
172+ ''|--|containers) remove_containers ;;
175173 images) lxc_delete_images_localy ;;
176174 ${LXC_HOST_PREFIX}-*)
177175 ! lxc_exists "$2" && usage_containers "unknown container: $2" && exit 42
@@ -185,7 +183,7 @@ main() {
185183 start|stop)
186184 sudo_or_exit
187185 case $2 in
188− ''|containers) lxc_cmd "$1" ;;
186+ ''|--|containers) lxc_cmd "$1" ;;
189187 ${LXC_HOST_PREFIX}-*)
190188 ! lxc_exists "$2" && usage_containers "unknown container: $2" && exit 42
191189 info_msg "lxc $1 $2"
@@ -203,7 +201,7 @@ main() {
203201 lxc exec -t "$3" -- "${LXC_REPO_ROOT}/utils/lxc.sh" __show suite \
204202 | prefix_stdout "[${_BBlue}$3${_creset}] "
205203 ;;
206− *) show_suite;;
204+ *|--) show_suite;;
207205 esac
208206 ;;
209207 images) show_images ;;
@@ -213,7 +211,7 @@ main() {
213211 ! lxc_exists "$3" && usage_containers "unknown container: $3" && exit 42
214212 lxc config show "$3" | prefix_stdout "[${_BBlue}${3}${_creset}] "
215213 ;;
216− *)
214+ *|--)
217215 rst_title "container configurations"
218216 echo
219217 lxc list "$LXC_HOST_PREFIX-"
@@ -228,7 +226,7 @@ main() {
228226 ! lxc_exists "$3" && usage_containers "unknown container: $3" && exit 42
229227 lxc info "$3" | prefix_stdout "[${_BBlue}${3}${_creset}] "
230228 ;;
231− *)
229+ *|--)
232230 rst_title "container info"
233231 echo
234232 lxc_cmd info
@@ -267,7 +265,7 @@ main() {
267265 ! lxc_exists "$3" && usage_containers "unknown container: $3" && exit 42
268266 lxc_exec_cmd "$3" "${LXC_REPO_ROOT}/utils/lxc.sh" __install "$2"
269267 ;;
270− '') lxc_exec "${LXC_REPO_ROOT}/utils/lxc.sh" __install "$2" ;;
268+ ''|--) lxc_exec "${LXC_REPO_ROOT}/utils/lxc.sh" __install "$2" ;;
271269 *) usage_containers "unknown container: $3" && exit 42
272270 esac
273271 ;;
utils/morty.sh+61−8
@@ -47,6 +47,7 @@ CONFIG_FILES=()
4747# Apache Settings
4848
4949APACHE_MORTY_SITE="morty.conf"
50+NGINX_MORTY_SITE="morty.conf"
5051
5152# ----------------------------------------------------------------------------
5253usage() {
@@ -54,9 +55,7 @@ usage() {
5455
5556 # shellcheck disable=SC1117
5657 cat <<EOF
57−
5858usage::
59−
6059 $(basename "$0") shell
6160 $(basename "$0") install [all|user]
6261 $(basename "$0") update [morty]
@@ -66,6 +65,7 @@ usage::
6665 $(basename "$0") inspect [service]
6766 $(basename "$0") option [debug-on|debug-off]
6867 $(basename "$0") apache [install|remove]
68+ $(basename "$0") nginx [install|remove]
6969 $(basename "$0") info [searx]
7070
7171shell
@@ -86,6 +86,9 @@ option
8686apache : ${PUBLIC_URL_MORTY}
8787 :install: apache site with a reverse proxy (ProxyPass)
8888 :remove: apache site ${APACHE_MORTY_SITE}
89+nginx (${PUBLIC_URL_MORTY})
90+ :install: nginx site with a reverse proxy (ProxyPass)
91+ :remove: nginx site ${NGINX_MORTY_SITE}
8992
9093If needed, set the environment variables in the '${DOT_CONFIG#"$REPO_ROOT/"}' file::
9194 PUBLIC_URL_MORTY: ${PUBLIC_URL_MORTY}
@@ -122,8 +125,6 @@ EOF
122125}
123126
124127main() {
125− rst_title "$SERVICE_NAME" part
126−
127128 required_commands \
128129 sudo install git wget curl \
129130 || exit
@@ -131,7 +132,7 @@ main() {
131132 local _usage="ERROR: unknown or missing $1 command $2"
132133
133134 case $1 in
134− --source-only) ;;
135+ --getenv) var="$2"; echo "${!var}"; exit 0;;
135136 -h|--help) usage; exit 0;;
136137
137138 shell)
@@ -147,6 +148,7 @@ main() {
147148 *) usage "$_usage"; exit 42;;
148149 esac ;;
149150 install)
151+ rst_title "$SERVICE_NAME" part
150152 sudo_or_exit
151153 case $2 in
152154 all) install_all ;;
@@ -185,6 +187,13 @@ main() {
185187 remove) remove_apache_site ;;
186188 *) usage "$_usage"; exit 42;;
187189 esac ;;
190+ nginx)
191+ sudo_or_exit
192+ case $2 in
193+ install) install_nginx_site ;;
194+ remove) remove_nginx_site ;;
195+ *) usage "$_usage"; exit 42;;
196+ esac ;;
188197 info)
189198 case $2 in
190199 searx) info_searx ;;
@@ -348,8 +357,8 @@ EOF
348357 wait_key
349358 fi
350359
351− if ! service_is_available "${PUBLIC_URL}"; then
352− warn_msg "Public service at ${PUBLIC_URL} is not available!"
360+ if ! service_is_available "${PUBLIC_URL_MORTY}"; then
361+ warn_msg "Public service at ${PUBLIC_URL_MORTY} is not available!"
353362 if ! in_container; then
354363 warn_msg "Check if public name is correct and routed or use the public IP from above."
355364 fi
@@ -363,7 +372,7 @@ EOF
363372 fi
364373
365374 local _debug_on
366− if ask_yn "Enable filtron debug mode (needs reinstall of systemd service)?"; then
375+ if ask_yn "Enable morty debug mode (needs reinstall of systemd service)?"; then
367376 enable_debug
368377 _debug_on=1
369378 else
@@ -436,6 +445,50 @@ This removes apache site ${APACHE_MORTY_SITE}."
436445 apache_remove_site "$APACHE_MORTY_SITE"
437446}
438447
448+install_nginx_site() {
449+
450+ rst_title "Install nginx site $NGINX_MORTY_SITE"
451+
452+ rst_para "\
453+This installs a reverse proxy (ProxyPass) into nginx site (${NGINX_MORTY_SITE})"
454+
455+ ! nginx_is_installed && err_msg "nginx is not installed."
456+
457+ if ! ask_yn "Do you really want to continue?" Yn; then
458+ return
459+ else
460+ install_nginx
461+ fi
462+
463+ "${REPO_ROOT}/utils/searx.sh" install uwsgi
464+
465+ SEARX_SRC=$("${REPO_ROOT}/utils/searx.sh" --getenv SEARX_SRC)
466+ SEARX_URL_PATH=$("${REPO_ROOT}/utils/searx.sh" --getenv SEARX_URL_PATH)
467+ nginx_install_app "${NGINX_MORTY_SITE}"
468+
469+ info_msg "testing public url .."
470+ if ! service_is_available "${PUBLIC_URL_MORTY}"; then
471+ err_msg "Public service at ${PUBLIC_URL_MORTY} is not available!"
472+ fi
473+}
474+
475+remove_nginx_site() {
476+
477+ rst_title "Remove nginx site $NGINX_MORTY_SITE"
478+
479+ rst_para "\
480+This removes nginx site ${NGINX_MORTY_SITE}."
481+
482+ ! nginx_is_installed && err_msg "nginx is not installed."
483+
484+ if ! ask_yn "Do you really want to continue?" Yn; then
485+ return
486+ fi
487+
488+ nginx_remove_site "$NGINX_MORTY_SITE"
489+
490+}
491+
439492rst-doc() {
440493
441494 eval "echo \"$(< "${REPO_ROOT}/docs/build-templates/morty.rst")\""
utils/searx.sh+2−6
@@ -114,9 +114,7 @@ usage() {
114114
115115 # shellcheck disable=SC1117
116116 cat <<EOF
117−
118117usage::
119−
120118 $(basename "$0") shell
121119 $(basename "$0") install [all|user|searx-src|pyenv|uwsgi|packages|buildhost]
122120 $(basename "$0") update [searx]
@@ -178,8 +176,6 @@ EOF
178176}
179177
180178main() {
181− rst_title "$SEARX_INSTANCE_NAME" part
182−
183179 required_commands \
184180 sudo systemctl install git wget curl \
185181 || exit
@@ -187,9 +183,8 @@ main() {
187183 local _usage="unknown or missing $1 command $2"
188184
189185 case $1 in
190− --source-only) ;;
186+ --getenv) var="$2"; echo "${!var}"; exit 0;;
191187 -h|--help) usage; exit 0;;
192−
193188 shell)
194189 sudo_or_exit
195190 interactive_shell "${SERVICE_USER}"
@@ -203,6 +198,7 @@ main() {
203198 *) usage "$_usage"; exit 42;;
204199 esac ;;
205200 install)
201+ rst_title "$SEARX_INSTANCE_NAME" part
206202 sudo_or_exit
207203 case $2 in
208204 all) install_all ;;
utils/templates/etc/nginx/default.apps-available/morty.confnew file+11
@@ -0,0 +1,11 @@
1+# https://example.org/morty
2+
3+location /morty {
4+ proxy_pass http://127.0.0.1:3000/;
5+
6+ proxy_set_header Host \$http_host;
7+ proxy_set_header Connection \$http_connection;
8+ proxy_set_header X-Real-IP \$remote_addr;
9+ proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
10+ proxy_set_header X-Scheme \$scheme;
11+}
utils/templates/etc/nginx/default.apps-available/searx.conf:filtronnew file+16
@@ -0,0 +1,16 @@
1+# https://example.org/searx
2+
3+location ${SEARX_URL_PATH} {
4+ proxy_pass http://127.0.0.1:4004/;
5+
6+ proxy_set_header Host \$http_host;
7+ proxy_set_header Connection \$http_connection;
8+ proxy_set_header X-Real-IP \$remote_addr;
9+ proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
10+ proxy_set_header X-Scheme \$scheme;
11+ proxy_set_header X-Script-Name ${SEARX_URL_PATH};
12+}
13+
14+location ${SEARX_URL_PATH}/static {
15+ alias ${SEARX_SRC}/searx/static;
16+}