V
V
Vladislav2019-04-09 23:32:47
Nginx
Vladislav, 2019-04-09 23:32:47

How to make access control to the site in Nginx?

Good day. Developed a site using Asp.net core, which consists of two parts.
1- The admin panel of an employee who will enter certain data and work with the database (mysite.com)
2-Api, with the help of which another user receives data from the database (mysite.com/api)
The task is this. It is necessary to differentiate access to the site from outside. So that access to the site api (mysite.com/api) is possible from outside, and access to the admin panel is only inside the network (from allowed addresses)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Wexter, 2019-04-09
@Lishin

nginx.org/ru/docs/http/ngx_http_access_module.html

O
Oval Enoc, 2019-04-09
@ovalenko

Password-protect access to the admin panel.

location ~* ^/admin {
        auth_basic                    "Admin page";
        auth_basic_user_file     /etc/nginx/nginx.pass;
    }

Create a password like this:
LOGIN="admin"
PASSWORD="pass"
OPENSSL=`echo "${PASSWORD}" | openssl passwd -1 -stdin -salt Nginx`
echo "${LOGIN}:${OPENSSL}" >>  /etc/nginx/nginx.pass

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question