There is a subdirectory in the nginx location code block, and the index.php in it reports 404.

background description

I want to put a project interface in the api.xxx.com domain name in the form of a subdirectory. For example, api.xxx.com/friends , this subdirectory is full of friends project interfaces.

related codes

my corresponding nginx configuration is as follows:
/ etc/nginx/conf.d/api.conf

server {
    server_name api.worldispoweredbymywife.top;
    root /var/www/api;

    location /friends/ {
        alias /var/www/api/friends/public/;
        index index.php;
        try_files $uri =404;
    }
    location ~ /friends/.+\.php$ {
        try_files $uri =404;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME /var/www/api/friends/public$fastcgi_script_name;
    }

    error_page 404 /404.html;
    location /404.html {
        root /usr/local/nginx/html/;
    }

    error_page 500 502 503 504 /50x.html;
    location =/50x.html {
        root /usr/local/nginx/html/;
    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

 -sharp managed by Certbot

    listen 443 ssl; -sharp managed by Certbot
    ssl_certificate /etc/letsencrypt/live/api.worldispoweredbymywife.top/fullchain.pem; -sharp managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/api.worldispoweredbymywife.top/privkey.pem; -sharp managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; -sharp managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; -sharp managed by Certbot

}

server {
    if ($host = api.worldispoweredbymywife.top) {
        return 301 https://$host$request_uri;
    } -sharp managed by Certbot


    server_name api.worldispoweredbymywife.top;
    listen 80;
    return 404; -sharp managed by Certbot


}

current problem

visiting https://api.worldispoweredbymywife.top/friends displays the 404 page that comes with nginx.
ps:
1. I put a index.html in / var/www/api/friends/public/ and then access
2 through https://api.worldispoweredbymywife.top/index.html. I commented out the two location of friends, which can be accessed directly through https://api.worldispoweredbymywife.top/friends/public/index.php.

ask the great god to save ~

Mar.06,2021

location ^~ /qr {
        alias /Users/whj/web/qr/public;
        try_files $uri $uri/ @qr;
        index index.php index.html index.htm;

        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/tmp/php-cgi.sock;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME /Users/whj/web/qr/public/index.php;
        }
    }

    location @qr {
        rewrite /qr/(.*)$ /qr/index.php?/$1 last;
    }

this is the nginx configuration of the subdirectory qr under my localhost. You can refer to

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b32c5e-2be59.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b32c5e-2be59.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?