For example, there is a website a.com, and there is an ajax.php file in the directory. Now it is required that only access to a.com (that is, bound to this domain name) is allowed to receive POST data. Other domain names such as b.com want to POST. When the data is sent to ajax.php, it will directly return 503 or the like. How to write it? I’m not familiar with nginx, it’s best to give specific examples, thank you~
I read the document and wrote a few lines of code to solve the problem. I will use this solution for the time being. If you have a better solution, please leave a message.
The code is posted below
Nginx can create multiple sites. That is server{}
in NginxCreate a default site first:
server {
server_name _;
root /var/nginx/html;
}
Create another site a.com:
server {
server_name a.com www.a.com;
root /data/www/a.com;
}
In this way, only a.com will be able to access files under the path a.com, and other domain names will access files under the default site /var/nginx/html.