To setup basic HTTP authentication with Nginx on CentOS 7, first install httpd-tools
.
[root@centos7 ~]# yum install -y httpd-tools
Create user and password:
[root@centos7 ~]# htpasswd -c /etc/nginx/.htpasswd pikedom New password: some_secure_password Re-type new password: some_secure_password Adding password for user opsview
Amend your Nginx vhost configuration:
[root@centos7 ~]# vim /etc/nginx/conf.d/mydownloads.opsview.com.conf
Add the following lines:
... auth_basic "Authentication Required: "; auth_basic_user_file /etc/nginx/.htpasswd; ...
Check and reload vhost configuration:
[root@centos7 ~]# nginx -t [root@centos7 ~]# systemctl restart nginx
Be the first to comment