S
S
shvets22019-01-05 21:29:27
Nginx
shvets2, 2019-01-05 21:29:27

Accepting requests only from a specific domain on nginx?

Hello. There is a main site sitename.ru and an API server located at api.sitename.ru. Both are powered by Nginx.
Is it possible to configure Nginx so that api.sitename.ru only accepts requests from sitename.ru?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mysterion, 2019-01-05
@Mysterion

if ($http_host != "sitename.ru")  {
  return 403;
}

if ($remote_addr != 127.0.0.1) {
  return 403;
}

But if there will be no requests from outside at all, it is better to hang the api site host on a different port and close this port from outside.

K
ky0, 2019-01-05
@ky0

If the site has a static address, the easiest way is to simply limit it by IP.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question