Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using Nginx as a reverse proxy to Apache which is handling PHP, here's my nginx site config:

server {
        listen   80 default;
        server_name  localhost;

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

        root /var/www/;

        location ~ \.php$ {
                proxy_pass    ;

        location ~ /\.ht {
                deny  all;

        #location / {
                try_files $uri @proxy;

        location @proxy {
                proxy_set_header        Host            $host;
                proxy_set_header        X-Real-IP       $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                client_max_body_size    10m;
                client_body_buffer_size 128k;
                proxy_connect_timeout   90;
                proxy_send_timeout      90;
                proxy_read_timeout      90;
                proxy_buffers           32 4k;
                proxy_pass    ;

My issue is that requests for index.php are being returned by nginx unparsed, so my location specifically for handling php files is not doing what it should.

If I request index.php?q=whatever, which is a valid request for apache, then the site returns a 500 with the error:

2012/07/13 11:22:27 [alert] 8490#0: *17994 4096 worker_connections are not enough while connecting to upstream, client:, server: localhost, request: "GET /index.php?q=whatever HTTP/1.0", upstream: "", host: ""
share|improve this question
nginx is just proxying, and shouldn't be doing anything with the PHP files. What's Apache's config look like for executing the PHP? – Shane Madden Jul 13 '12 at 3:35
up vote 3 down vote accepted
    location ~ \.php$ {
            proxy_pass    ;

In your configuration, Nginx is listening in port 80. So passing index.php file to Nginx (port 80) will leave it unparsed. So, assuming that Apache listens on port 81, the correct proxy_pass directive would be...

    location ~ \.php$ {
            proxy_pass    ;

To know more about how Nginx handles proxy requests, please check out the official wiki on HttpProxyModule.

share|improve this answer
Haha, oops, I'll fix that ASAP and see how it goes! I had originally ran nginx on 81 to leave apache on 80 as it was originally. That'll teach me to DRY. – DanH Jul 13 '12 at 11:29
That solved everything, thanks! :) – DanH Jul 15 '12 at 8:35
I'm glad it worked for you, @DanH! – Pothi Jul 15 '12 at 10:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.