0

Here is the relevant part of my Nginx configuration file:

http {
    log_format  fastcgi
                '$remote_addr - $remote_user [$time_local] "$request" '
                '$status $body_bytes_sent "$http_referer" '
                '"$fastcgi_script_name" "$fastcgi_path_info"';

    server {
        listen       8080;
        server_name  localhost;

        access_log  /usr/local/var/log/nginx/access.log  fastcgi;

        location / {
            fastcgi_index /;
            fastcgi_pass unix:/usr/local/var/www/run/httpd.sock;
            include fastcgi_params;
        }
    }
}

Basically I have a Unix socket at /usr/local/var/www/run/httpd.sock which handles FastCGI requests, and it works quite well. The problem here is that Nginx thinks the last part of the URI is the script name, but it should be the path info. For example

⇒ nginx -v
nginx version: nginx/1.15.0
⇒ nginx
⇒ curl -i localhost:8080/index
HTTP/1.1 200 OK
Server: nginx/1.15.0
Date: Tue, 10 Jul 2018 12:27:15 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive

<p>hello, world</p>
⇒ tail -n 1 /usr/local/var/log/nginx/access.log
127.0.0.1 - - [10/Jul/2018:20:27:15 +0800] "GET /index HTTP/1.1" 200 30 "-" "/index" ""

This means $fastcgi_script_name is /index, with $fastcgi_script_name being an empty string.

How can I configure Nginx to make $fastcgi_script_name to contain the last part of a URI, i.e. things like /index?

1

Firstly in your location block you have this directive include fastcgi_params;

So presumably in the same directory as your nginx.conf you will find a file called fastcgi_params which is going to contain a load of configuration options pertaining to this kind of thing, so check that first.

If that's all as you want it then you can use the fastcgi_split_path_info directive in your location block to define two regex captures from the request uri, one for the fastcgi_path_info variable and the other for the fastcgi_script_name variable

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.