LoginSignup
0
0

More than 3 years have passed since last update.

【nginx】[FAIL] Starting nginx: nginx failed!の対処

Last updated at Posted at 2021-04-09

nginxは初めて使うので、不慣れでエラー対処しながら進めてます。
今回、GCP上にnginxを構築していて、実行したコマンドは以下
501 sudo apt update
502 sudo apt install nginx
503 nginx -v
504 sudo apt install -y ufw
505 sudo ufw allow 'Nginx HTTP'←ここがわるかったのかな?

ということで、タイトルの内容を進めていきます。

エラー

nginxを起動しようとしましたが、以下のエラーが発生。

systemctl status nginx

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

これは、systemctlが使えないことが原因のため、以下のコマンドで対処するが、掲題のエラーが発生。
sudo service nginx start

[FAIL] Starting nginx: nginx failed!

nginxを起動しようとすると、Address already in useと言われ再起動できない。

$ sudo /usr/sbin/nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

調べた結果

nginxで使うポートを先に何かのポートが使っているとだめみたい。

sudo netstat -lntp

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 106/sshd
tcp 0 0 127.0.0.1:43607 0.0.0.0:* LISTEN 518/sshd:
tcp 0 0 127.0.0.1:8998 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:65001 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN -
tcp6 0 0 :::980 :::* LISTEN -
tcp6 0 0 :::22 :::* LISTEN 106/sshd
tcp6 0 0 :::922 :::* LISTEN -
tcp6 0 0 :::970 :::* LISTEN 81/theia-proxy

邪魔なプロセスをキルすればいいみたいだけど、
かぶってない気がするが、見方がわからない・・・

以下のディレクトリで、nginxのデフォルトポートを確認すると80だったので、81に変更した。
vim /etc/nginx/sites-enabled/default

links コマンドでみてみると、welcome ngnxとでるので、起動できている気がするが、
外部IPから接続できない。。。

今回GCPに構築したのだが、おそらくネットワークの設定を変更しないと行けないのではないかと。
ポートを変更したから http://IPアドレス:81/としたけど、できない

結果

GCPで構築してたんですが、仮想マシンにログインせずに作業していたというオチでした。。。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0