惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
L
LangChain Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Recent Announcements
Recent Announcements
大猫的无限游戏
大猫的无限游戏
罗磊的独立博客
MongoDB | Blog
MongoDB | Blog
博客园 - 【当耐特】
博客园 - 叶小钗
I
InfoQ
MyScale Blog
MyScale Blog
H
Help Net Security
月光博客
月光博客
Vercel News
Vercel News
B
Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
Netflix TechBlog - Medium
宝玉的分享
宝玉的分享
WordPress大学
WordPress大学
GbyAI
GbyAI
Blog — PlanetScale
Blog — PlanetScale
博客园 - Franky

Ittavern.com

Wimage - Hosting Open-Source Image Uploader with Podman and external S3 Storage Switching from Hugo to picopaper Encryption using SSH Keys with age in Linux ETag in nginx - Simple Resource Caching Sending nginx Logs to Loki with Grafana Alloy How to: Cisco ISE backup to SFTP repository with public key authentication Dummy IP & MAC Addresses for Documentation & Sanitization Deploying ISSO Commenting System for Static Content using Docker Generate a Vanity v3 Hidden Service Onion Address with mkp224o ssh-audit Primer - Audit your SSH Server mtr - More Detailed Traceroute - Network Troubleshooting My Personal Backup Strategy - August 2024 iperf3 - User Authentication with Password and RSA Public Keypair Adding a trash can to Linux with trash-cli Bandwidth Measurement using netcat on Linux Getting started with rsync - Comprehensive Guide Cron Jobs on Linux - Comprehensive Guide with Examples SSH Server Hardening Guide v2 Port Knocking with knockd and Linux - Server Hardening Getting started with rclone - Data transmission Getting started with dig - DNS troubleshooting Getting started with Fail2Ban on Linux Getting started with netcat on Linux with examples URL explained - The Fundamentals Troubleshooting Asking The Right Questions Create tmux layouts using bash scripts Getting started with tcpdump - Ittavern.com Curl on Linux - Reference Guide Getting started with nmap scripts My Offsite Backup - March 2023
nginx - simple and native authentication function
2022-12-11 · via Ittavern.com

Important disclaimer: This solution is not secure! - It is fine for a quick and temporary solution for your local network, but it is not a secure solution for important ressources that are available over the internet.

As a side note: without TLS (HTTPs), the credentials will be sent in plain text, and are easily accessable.

Creating the user #

Even though you could do it per hand, it is recommended to use the Apache utility to create the user.

The package needed is called apache2-utils for Debian derivatives and httpd-tools for RHEL derivatives.

sudo htpasswd -c /etc/nginx/htpasswd AzureDiamond # The username is case-sensitive and the path and name of the password file can be changed

Now it is time to choose a secure password:

New password:
Re-type new password:
Adding password for user AzureDiamond

You now can find the password file with the hashed password in the location of your choice:

cat /etc/nginx/htpasswd
AzureDiamond:$apr1$8xZ0m9Yq$NVBN9veofzoV9vBoBK7z40

Side note: You can remove a user with the following command:

sudo htpasswd -D /etc/nginx/htpasswd AzureDiamond # remember to choose the correct file

Change your nginx config #

We can now add 2 line to our server or location segment to activate the authentication feature:

auth_basic "You shall not pass!";
auth_basic_user_file /etc/nginx/htpasswd;

Check the nginx config with sudo nginx -t and if it confirms the correct syntax, restart the nginx service with sudo systemctl restart nginx.

You can test it here: https://ittavern.com/azurediamond

Exclude subdirectories #

If you, for example, add the authentication to the root directory of your site, you can exclude chosen subdirectories by adding the following line to the location segment:

location /api/ {
        auth_basic off;
}

White- / blacklist IPs #

More step further, just work with white- and blacklists by adding chosen IPs like this to the chosen segment:

    deny  8.8.8.8;
    allow 9.9.9.9;
    allow 10.10.10.0/24;
    deny  all;

Special thanks to ruffy, for informing me about the processes behind it and the security risks.