问题
I've created a subdomain to host our API. I'm trying to figure out how to configure nginx to only allow requests to the API location (/2/, which would look like https://api.example.com/2/) and return 404s for all other requests to api.example.com
We're using PHP with a pretty standard PHP setup--routing most requests through index.php and matching php as show below:
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php last;
}
location ~ \.php$ { config here; }
I'm hoping I'm over-thinking this and that there is a simple solution.
回答1:
Just configure the /2 location and mark every thing else as 404
location / {
return 404;
}
location /2 {
try_files $uri /2/index.php$request_uri;
}
location ~ \.php$ { config here; }
来源:https://stackoverflow.com/questions/17636503/return-404-with-nginx-to-all-locations-except-for-one