3

THere is a piece of legacy code I'm working on, I can't alter where it POSTs to so I just need to figure a way around it.

THe bit of Javascript makes a post as follows -

POST /authentication/login/

which is pretty weird given that it is posting to a directory, but anyway I want to configure Nginx to accept posts to this location and then pass them to a bit of PHP in my Nginx config I have the following inside a http block

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   html;
        index  index.html index.htm;
    }

    location /authentication/login/ {

       index hello.php;
       #root html;
       #index /usr/local/nginx/html/hello.php; 


    }


location ~.php$ {
    include /usr/local/nginx/conf/fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
}
}

The php stuff works, I can go direct to the hello.php and that works.

My error logs/ access logs don't really give me to much. I was getting a 404 on the hello.php but fixed that by putting the "index" in. However that never ended up calling the bit of php. I've also tried putting the fastcgi stuff into the /authenticate/login/ location within the nginx.conf.

At the crux of it, if I post something to /authenticate/login I want to call a piece of php to return the necessary values.

What is the correct way to write that location block? Any ideas?

  • Are you sure it's hitting /authentication/login/ and not /authentication/login instead? – Drew Khoury Apr 30 '13 at 8:29
0

You'll need to specify exact location to make nginx process it before ~.php {} block, copy fastcgi parametrs so url will be passed to the php and change the uri with rewrite rule. Config block with login location should look something like this:

location = /authentication/login/ {
    rewrite ^(.*) /hello.php last;
    include /usr/local/nginx/conf/fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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