Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm working on a test setup for nginx+apache. I have nginx listening on port 80, apache on port 8080. Nginx is set up to deal out the static content, apache is there to deal out the dynamic content (at least until we can upgrade to php 5.3). My apache setup works fine, here's the server section for nginx:

server {

    listen           80;
    server_name  mediocregopher-test;
    index test.php;

    location ~ \.php$ {
        proxy_pass   http://127.0.0.1:8080;
    }

    location ~ /\.ht {
        deny  all;
    }

    location / {
        root   /var/www/html;
    }
}

The issue is, my index page (test.php) needs to be proxy'd to apache as "127.0.0.1:8080/test.php" when someone requests "mediocregopher-test:80/". With this setup this isn't happening. I'm fairly new to nginx, but I've looked around and couldn't find any setups that would solve this (although the problem is so simple it seems like it would be). Any suggestions?

I'm using nginx 1.0.1, if that's at all relevant.

share|improve this question
    
There is no special setup required for an index page that should be proxied (i.e. if you have proxying working, it will work for the index page). I presume you have verified that Nginx will serve a static file (just make that 'test.htm' and create the file) to ensure that all other aspects of the Nginx setup are valid (i.e. it recognizes the server name, etc). You can also use the 'debug' parameter on error_log to help provide more information. Also - check your Apache log. (If you turn off Apache, a proxied request should return 'Bad Gateway') –  cyberx86 Jul 6 '11 at 2:24
    
cyberx86 is correct that your setup is fine. In addition to making sure it's going to the right server block, make sure you've also reloaded the configuration. It isn't reparsed on every page load like .htaccess is. –  Martin Fjordvald Jul 6 '11 at 10:19
add comment

2 Answers

up vote 1 down vote accepted

Add

location = / {
  proxy_pass http://127.0.0.1:8080/test.php;
}
share|improve this answer
add comment

Nginx sends the request to Apache as soon as it realizes that the requested URL ends on .php, so you should add the following line to your Apache configuration file:

DirectoryIndex test.php

You can find more information about DirectoryIndex and its scope on this URL:

http://httpd.apache.org/docs/2.2/mod/mod_dir.html#directoryindex

share|improve this answer
add comment

Your Answer

 
discard

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.