Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8239503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:10:07+00:00 2026-06-07T20:10:07+00:00

I’m trying to run php5 on AmazonEC2 with multi separated php-fpm servers load balanced

  • 0

I’m trying to run php5 on AmazonEC2 with multi separated php-fpm servers load balanced by upstream block on nginx.conf. I’m testing with two t1.micro instances, but getting 502 Bad Gateway error on my browser when I try loading php files. (Static html files are working fine, but cant get php files to work.)

Here is my nginx error logs.

2012/07/11 12:28:21 [error] 18626#0: *1 recv() failed (104: Connection
reset by peer) while reading response header from upstream, client:
xxx.xxx.xxx.xxx, server: http://www.example.com, request: “GET / HTTP/1.1”,
upstream: “fastcgi://10.xxx.xxx.xxx:9000”, host: “www.example.com”

and sometimes I get this.

2012/07/11 13:25:51 [error] 1157#0: *4 upstream prematurely closed
connection while reading response header from upstream,
client:xxx.xxx.xxx.xxx, server: http://www.example.com, request: “GET /
HTTP/1.1”, upstream: “fastcgi://10.xxx.xxx.xxx:9000”, host:
“www.example.com”

I spent time on opening 9000 port from ec2 sequrity groups/iptables and also declaring local ip addresses on both nginx and php-fpm so I’m thinking that’s not a problem. (I used to have connection refused error logs)

Could anyone help me out??
Below are my server settings and preferences.

[instance 1]

  • t1.micro CentOS 6.2.2
  • nginx/1.2.2

[instance 2]

  • t1.micro CentOS 6.2.2
  • PHP 5.3.14 (fpm-fcgi) Zend Engine v2.3.0 with eAccelerator v0.9.6

[nginx.conf]

user  nginx nginx;
worker_processes  1;
worker_rlimit_nofile 1024;
worker_priority -5;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    multi_accept on;
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    server_tokens   off;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  0;

    gzip  on;

    upstream apserver {
        ip_hash;
        server ip-10-xxx-xxx-xxx.ap-northeast-1.compute.internal:9000;
    }

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

[example.conf]

server {
    listen       80;
    server_name  www.example.com;

    charset utf-8;
    access_log  /var/log/nginx/www.example.com.access.log  main;
    error_log   /var/log/nginx/www.example.com.error.log  debug;
    root    /var/www;

    location / {
        index   index.php index.html index.html;
        if (-f $request_filename) {
            expires max;
            break;
        }

        if (!-e $request_filename) {
            rewrite ^(.+)/index\.php/(.*)$ $1/index.php?q=$2 last;
        }
    }

        location ~ \.php$ {
        fastcgi_send_timeout  10m;
            fastcgi_read_timeout 10m;
        fastcgi_connect_timeout 10m;
        fastcgi_pass    apserver;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME     $document_root$fastcgi_script_name;
        fastcgi_param   PATH_INFO       $fastcgi_script_name;
        include     /etc/nginx/fastcgi_params;
    }
}

[php-fpm.d/www.conf]

[www]
listen = ip-10-xxx-xxx-xxx.ap-northeast-1.compute.internal:9000
listen.backlog = -1
listen.allowed_clients = ip-10-yyy-yyy-yyy.ap-northeast-1.compute.internal

; Tried testing with below and got the same error
;listen = 9000
;listen.allowed_clients = any

listen.owner = prod
listen.group = prod
listen.mode = 0666
user = prod
group = prod

pm = dynamic
pm.max_children = 10
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 8
pm.max_requests = 500

request_terminate_timeout = 30
request_slowlog_timeout = 2
slowlog = /var/log/php-fpm/www-slow.log

php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_admin_flag[expose_php] = off
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T20:10:10+00:00Added an answer on June 7, 2026 at 8:10 pm

    Finally I’ve figured this out!!

    I’m still not sure why but by allocating elastic ip’s on each of my instances, and using the Private IP instead of Private DNS Addresses solved my problem.

    so my conf files now looks like this just in case.

    [nginx.conf]

    upstream apserver {
        ip_hash;
        server 10.xxx.xxx.xxx:9000;
    }
    

    [php-fpm.d/www.conf]

    [www]
    listen = 10.xxx.xxx.xxx:9000
    listen.backlog = -1
    listen.allowed_clients = 10.yyy.yyy.yyy
    

    Thanks!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.