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 ~