Very new to Nginx so please be patient. We have just acquired a VPS and are starting to run Docker-based webservers on it. However, some of those webservers should not be publicly accessible. While I believe that we could restrict the IP address allowed to connect to the webservers, it seems more convenient to simply set up a password-based authentification and we want to use Nginx for this.
First of all, we got the Nginx-based authentification to work for the general port 80 access to the VPS. However, despite looking around for help, we cannot find a way to also password-protect access to <vps-ip>:<webserver-port> (port 5000, in our case).
Here is what our config file currently looks like:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
}
When checking the syntax, everything seems ok and we can successfully restart nginx. However, the webserver is still accessible and there is no request for a password.
Besides that, it is often better idea to not make any service publicly accessible unless itâs necessary. So where applicable - instead of blocking public access to specific service one way or another, you can ie. make it accessible only locally/internally by listening on loopback address like: