起動時にnginxを起動しようとすると、次のエラーが発生しました Raspbian GNU/Linux 8 (jessie)
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
Active: failed (Result: exit-code) since Sun 2016-08-07 10:38:50 EDT; 1min 10s ago
Process: 478 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
私の設定は正常に機能し、ログイン後にnginxを起動できます。しかし、systemdで起動することはできません。
これが私のユニットファイルです:
# 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=syslog.target network.target remote-fs.target nss-lookup.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
/lib/systemd/system/nginx.service
これを開始するには、どのターゲットが必要ですか?私はすでに試しましたnetwork-online.target
(これが最も理にかなっており、同じ結果を受け取りました。
更新
この投稿のおかげでいくつか変更を加え、nginxを起動しました...それでもエラーで失敗します。
/etc/systemd/system/mult-user.target.wants/nginx.service
を含むように変更されました:
After=network-online.target
Wants=network-online.target
After=network.target
sudo systemctl enable systemd-networkd-wait-online.service
、それを起動します(をnetwork-online.target
使用して有効にすることはできないためsudo systemctl enable network-online.target
)sudo systemctl enable nginx
systemd-analyze plot > something.svg
を検索しましたnginx.service
が、ファイルは存在していましたが、正常に起動せず、代わりにリバースプロキシサーバーに関するエラーが発生しました。解決方法がわかりませんが、それは別の質問のトピック。以下は、systemd-analyzeプロットから取得した画像です。
ただし...マシンを起動して実行するsudo systemctl start nginx
と、問題なく起動します。
エラーログからのエラーメッセージは次のとおりです。
2017/05/16 13:12:53 [emerg] 555#0: host not found in upstream "somehost.somedomain.lan" in /etc/nginx/sites-enabled/siteconf:41
問題の構成行は次のとおりです。
server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6
# Make site accessible from http://localhost/
server_name somehost somehost.somedomain.lan;
# Note: There should never be more than one root in a
# virtual host
# Also there should never be a root in the location.
#root /var/www/nginx/;
location ^~ / {
resolver 127.0.0.1 valid=300s; # NOTE: Added this to resolve it.
access_log ./logs/RootWiki_access.log;
error_log ./logs/RootWiki_error.log;
proxy_buffers 16 4k;
proxy_buffer_size 2k;
proxy_set_header Host $host;
proxy_set_header X-Real_IP $remote_addr;
rewrite /(.*) /$1 break;
proxy_pass http://wiki.leerdomain.lan:8080; # NOTE: This one causes the error according to the error log.
}
これが機能するようになりました:
# 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=multi-user.target
Requires=network-online.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
Unit
セクションの下に私は以下を追加しました:
[Unit]
# ...
After=multi-user.target
Requires=network-online.target
/lib/systemd/system/nginx.service
また、bashで以下を実行しました。
$ sudo systemctl enable nginx
次に、シンボリックリンクが表示されることを確認します。
$ ls -la /etc/systemd/system/multi-user.target/wants
...
lrwxrwxrwx 1 root root 33 May 14 2016 nginx.service -> /lib/systemd/system/nginx.service
...
次に、デーモンをリロードします。
$ sudo systemctl daemon-reload
最後に再起動して、そこにあるかどうかを確認します。
$ sudo systemctl status --state active | grep nginx
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加