LoginSignup
19
13

More than 5 years have passed since last update.

EC2にnginx+php(php-fpm socket)環境を最速で構築したときにハマった事

Posted at

初投稿はQiitaで見た記事どおりに、知識無しで丸っと真似るとしてハマったこと。

参考

事象

  • コマンド上でのphpファイルは動くが、WEB経由だと50Xエラー
  • htmlファイルは問題なく表示される。
[error] xxxx#0: *9 connect() failed (111: Connection refused) while connecting to upstream,
 client: 192.168.xxx.xxx, server: example.com, request: "GET /xxx.php HTTP/1.1", upstream:
 "fastcgi://127.0.0.1:9000", host: "example.com"

確認

//起動してる?
# service nginx status 
nginx (pid  xxxx) is running...

# service php-fpm status
php-fpm-5.6 (pid  xxxx) is running...

//OK!

//バージョンによる?
# nginx -v
nginx version: nginx/1.8.1

# php-fpm -v
PHP 5.6.17 (fpm-fcgi) (built: xxxxx)

問題の箇所

暫くググッてみたけど、全く同じ状況のもの記事が無かった…
もう一度設定ファイルを見直す。

/etc/nginx/nginx.conf
include /etc/nginx/conf.d/*.conf;

インクルードされてるよ。

php-fpm.conf
upstream php-fpm {
        server 127.0.0.1:9000;
}

参考ではnginxとphp-fpmはソケット通信にしていたよね。
そしてセキュリティグループでポート閉じてたよね?

# lsof -i tcp:9000
# (ち~ん)

# lsof -i tcp:80
COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   xxxx  root    6u  IPv4  xxxxx      0t0  TCP *:http (LISTEN)

解決

それぞれのインクルードファイルをソケットに書き換え終了。
正常にWEB経由でphpが実行される事を確認!

19
13
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
19
13