nginx访问index.php 404,nginx location代码块下放了个子目录,里面的index.php报404

背景描述

我想在api.xxx.com域名下放个项目接口,以子目录的形式。比如api.xxx.com/friends,这个子目录下都是friends这个项目的接口。

相关代码

我的对应的nginx配置如下:

/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;

}

# managed by Certbot

listen 443 ssl; # managed by Certbot

ssl_certificate /etc/letsencrypt/live/api.worldispoweredbymywife.top/fullchain.pem; # managed by Certbot

ssl_certificate_key /etc/letsencrypt/live/api.worldispoweredbymywife.top/privkey.pem; # managed by Certbot

include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot

ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {

if ($host = api.worldispoweredbymywife.top) {

return 301 https://$host$request_uri;

} # managed by Certbot

server_name api.worldispoweredbymywife.top;

listen 80;

return 404; # managed by Certbot

}

当前问题

访问https://api.worldispoweredbymywife.top/friends会显示nginx自带的404页面。

ps:

1.我在/var/www/api/friends/public/下放了个index.html然后通过https://api.worldispoweredbymywife.top/index.html是可以访问的

2.我把friends的两个location注释掉,直接通过https://api.worldispoweredbymywife.top/friends/public/index.php是可以访问的。

求大神解救~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值