
ngx_pagespeedを使用してnginxをインストールする必要があります。私は次のディレクティブを使用します。 https://github.com/pagespeed/ngx_pagespeed#how-to-build
しかし、インストールが完了したら、nginxファイルは次のようになります。
/usr/local/nginx/sbin/nginx
/usr/local/nginx/conf/nginx.conf
/usr/local/nginx/logs/nginx.pid
ここにはnginx起動スクリプトはありません。
/etc/init.d
次のようにnginxを実行できません。
service nginx start
そしてnginxは自動的に実行されません。
次のようにnginxをインストールすると:
sudo apt-get install nginx
Nginxの場所:
/usr/sbin/nginx
/etc/nginx/nginx.conf
/run/nginx.pid
次のようにnginxを起動できます。
service nginx start
サーバーが再起動すると、nginxが自動的に起動し、nginxプロセスの所有者はwww-dataです。
私の質問。 ngx_pagespeedを使用していますが、標準設定のようにnginxをインストールできますか? :
- 場所: /usr/sbin/, /etc/nginx/, /run/
- 「サービスnginxの起動/再起動/停止」開始
- サーバーの再起動後の自動ロードプロセス
- プロセス所有者www-dataを使用する
答え1
nginx自体にはinitスクリプトは含まれていません。初期化スクリプトは、オペレーティングシステムとnginxビルドパラメータによって異なります。このスクリプトはリポジトリの貢献者によって指定されます。
ソースからnginxをインストールする場合https://github.com/pagespeed/ngx_pagespeed#how-to-buildその後、独自の初期化スクリプトを作成する必要があります。
$ sudo nano /etc/init.d/nginx
OSバージョン、nginxビルドパラメータに従って初期化スクリプトを貼り付けます。
それから:
$ sudo chmod +x /etc/init.d/nginx
$ sudo /usr/sbin/update-rc.d -f nginx defaults
$ # start service
$ sudo service nginx start
$ # make it autostart
$ sudo chkconfig nginx on
例initスクリプト(インストールディレクトリを変更しないと仮定):
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/sbin/nginx
NAME=nginx
DESC=nginx
test -x $DAEMON || exit 0
# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
. /etc/default/nginx
fi
set -e
. /lib/lsb/init-functions
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON || true
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile \
/usr/local/nginx/logs/$NAME.pid --exec $DAEMON || true
sleep 1
start-stop-daemon --start --quiet --pidfile \
/usr/local/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON || true
echo "$NAME."
;;
status)
status_of_proc -p /usr/local/nginx/logs/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
exit 1
;;
esac
exit 0
まだディレクトリの場所を変更しますか?
ソースコードのコンパイルhttps://github.com/pagespeed/ngx_pagespeed#how-to-build、
ただし、次のパラメータをすべて./configureに追加する必要があります。
--prefix=/etc/nginx
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-client-body-temp-path=/var/lib/nginx/body
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi
--http-log-path=/var/log/nginx/access.log
--http-proxy-temp-path=/var/lib/nginx/proxy
--http-scgi-temp-path=/var/lib/nginx/scgi
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi
--lock-path=/var/lock/nginx.lock
--pid-path=/var/run/nginx.pid
次に、独自の初期化スクリプトを作成します。
#!/bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/nginx
NAME=nginx
DESC=nginx
# Include nginx defaults if available
if [ -f /etc/default/nginx ]; then
. /etc/default/nginx
fi
test -x $DAEMON || exit 0
set -e
. /lib/lsb/init-functions
test_nginx_config() {
if $DAEMON -t $DAEMON_OPTS >/dev/null 2>&1; then
return 0
else
$DAEMON -t $DAEMON_OPTS
return $?
fi
}
case "$1" in
start)
echo -n "Starting $DESC: "
test_nginx_config
# Check if the ULIMIT is set in /etc/default/nginx
if [ -n "$ULIMIT" ]; then
# Set the ulimits
ulimit $ULIMIT
fi
start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
--exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
--exec $DAEMON || true
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile \
/var/run/$NAME.pid --exec $DAEMON || true
sleep 1
test_nginx_config
# Check if the ULIMIT is set in /etc/default/nginx
if [ -n "$ULIMIT" ]; then
# Set the ulimits
ulimit $ULIMIT
fi
start-stop-daemon --start --quiet --pidfile \
/var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
test_nginx_config
start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid \
--exec $DAEMON || true
echo "$NAME."
;;
configtest|testconfig)
echo -n "Testing $DESC configuration: "
if test_nginx_config; then
echo "$NAME."
else
exit $?
fi
;;
status)
status_of_proc -p /var/run/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
;;
*)
echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" >&2
exit 1
;;
esac
exit 0
答え2
NGINXがインストールされているリポジトリにPageSpeedを追加し、パッケージと実行マネージャの両方に統合したいと思います。考えてみてはいかがでしょうか?インストールされているNGINXに動的PageSpeedモジュールをロードします。?
systemd
これはこれを行うBashスクリプトです(Ubuntu 18.04 LTSで使用されています)。
#!/bin/bash
# https://www.majlovesreg.one/tag/code/
# https://www.majlovesreg.one/adding-pagespeed-to-a-running-nginx-instance
# For custom NGINX version, use:
# ngver=1.14.2
# For passing via the command line, use:
# ngver=$1
# For automated detection of installed NGINX, use:
ngver=$(nginx -v 2>&1 | grep -oP '(?<=/).*')
moddir=/usr/share/nginx/modules
builddir=$(mktemp -d)
# Build in tmp directory
cd ${builddir}
# Use script provided by pagespeed
nice -n 19 ionice -c 3 bash <(curl -f -L -sS https://ngxpagespeed.com/install) -n ${ngver} -m -b ${builddir} -a '--with-compat' -y || { echo '!! error with module creation, exiting...'; exit 1; }
# Replace ngx_pagespeed.so if exists, otherwise, copy it
[ -f ${moddir}/ngx_pagespeed.so ] && sudo mv ${moddir}/ngx_pagespeed.so ${moddir}/ngx_pagespeed.so.old
sudo chmod 644 /usr/local/nginx/modules/ngx_pagespeed.so || { echo '!! error with module path, exiting...'; exit 2; }
sudo cp /usr/local/nginx/modules/ngx_pagespeed.so ${moddir}/
# If new module works well, clean up build and install files
sudo nginx -t && { sudo rm -r /usr/local/nginx; rm -r ${builddir}/incubator-pagespeed-ngx-latest-stable; rm -r ${builddir}/nginx-${ngver}; } || { echo '!! nginx conf failed, exiting...'; exit 4; }
# Restart NGINX
systemctl is-active nginx && sudo systemctl restart nginx || sudo systemctl start nginx
echo
systemctl --no-pager status nginx
echo
echo 'Build and install of ngx_pagespeed sucessful!'
echo
構成と設定については、以下を確認してください。https://www.majlovesreg.one/adding-pagespeed-to-a-running-nginx-instance。