Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

初投稿は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が実行される事を確認!

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away