
私はDebian 8サーバーにnginx 1.9をインストールしました。 nginxを実行しようとすると正常に動作しますが、起動時にnginxを自動的にロードしないようです。
インターネットで推奨される多くの初期化スクリプトを試しましたが、まだ何も機能していません。今私はこの問題を解決するためにsystemctlを使用しようとしています。
~$ systemctl status nginx
● nginx.service
Loaded: masked (/dev/null)
Active: inactive (dead)
~$ sudo systemctl try-restart nginx
Failed to try-restart nginx.service: Unit nginx.service is masked.
~$ sudo systemctl reload nginx
Failed to reload nginx.service: Unit nginx.service is masked.
~$ sudo systemctl reload nginx
Failed to reload nginx.service: Unit nginx.service is masked.
残念ながら、「サービスのブロック」が何を意味するのか、なぜブロックされるのかわかりません。
私が走るとき
sudo nginx
サーバーは素晴らしい実行しています。次に、nginxサービスのマスクを解除する方法を見ました。
~$ sudo systemctl unmask nginx.service
Removed symlink /etc/systemd/system/nginx.service.
さて、私はsystemctlを使ってnginxを起動することができます。だから再起動すると、nginxが自動的にロードされることを確認しました。しかし、それは失敗し、私は次にどこに行くべきかわからなかった。
誰かが起動時にnginxを自動的に実行するのに役立ちますか?
答え1
有効化、実行、ブロック操作を混同しているようです。
systemctl start
、systemctl stop
:開始(停止)関連ユニットまもなく;systemctl enable
、systemctl disable
:単位表示(表示解除)起動時に自動的に起動(該当セクションに記載されている単位別の方法で[Install]
)systemctl mask
、systemctl unmask
::関連ユニットを実行しようとするすべての試みは許可されていません(手動またはデフォルトの実行ターゲットの依存関係を含む他のユニットの依存関係として)。 systemd での自動起動の表示は、デフォルトの実行ターゲットの人為的な依存関係を関連デバイスに追加することによって行われるため、「マスク」も自動起動を許可しません。
したがって、これは別のタスクです。あなたが欲しいものsystemctl enable
。
参照番号:システム制御(1)。
追加情報:Lennart Poettering(2011-03-02)。 「三つのレベルの閉鎖」。 管理者向けシステム。 0pointer.de.
答え2
正しいページにリダイレクトすることを許可された回答のリンクを修正しました。しかし、関連内容は次のとおりです。
sudo systemctl enable nginx.service
sudo systemctl start nginx.service
sudo systemctl status nginx.service
次のようになります/lib/systemd/system/nginx.service
。
# Stop dance for nginx
# =======================
#
# ExecStop sends SIGSTOP (graceful stop) to the nginx process.
# If, after 5s (--retry QUIT/5) nginx is still running, systemd takes control
# and sends SIGTERM (fast shutdown) to the main process.
# After another 5s (TimeoutStopSec=5), and if nginx is alive, systemd sends
# SIGKILL to all the remaining processes in the process group (KillMode=mixed).
#
# nginx signals reference doc:
# http://nginx.org/en/docs/control.html
#
[Unit]
Description=A high performance web server and a reverse proxy server
After=network.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target
`
答え3
これは私にとって効果的です。 https://web.archive.org/web/20150328063215/https://longhandpixels.net/blog/2014/02/install-nginx-debian-ubuntu
私は特に他のバージョンのnginxコンパイルに関するほとんどのドキュメントを無視し、「自動的に起動するように設定」しました。
そこの指示に従い、再起動するとnginx 1.9が実行されています。
皆様のご支援と洞察に心から感謝します。みんなありがとうございます!
答え4
nginxリソースからhttps://www.nginx.com/resources/wiki/start/topics/examples/systemd/
echo "
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
" > /lib/systemd/system/nginx.service