首页 > 系统相关 >nginx总结

nginx总结

时间:2024-10-24 14:31:52浏览次数:1  
标签:总结 auth server nginx htpasswd basic password

使用auth_basic控制访问

  • nginx代理的网站,直接访问如果需要添加安全性,如需要输入用户名+密码才能访问页面,可以通过nginx的auth_baisc配置来实现

检查htpasswd

一般nginx的安装之后会自带或者nginx容器镜像自带

root@ea6255db9f51:/config/nginx/site-confs# htpasswd
Usage:
        htpasswd [-cimBdpsDv] [-C cost] passwordfile username
        htpasswd -b[cmBdpsDv] [-C cost] passwordfile username password

        htpasswd -n[imBdps] [-C cost] username
        htpasswd -nb[mBdps] [-C cost] username password
 -c  Create a new file.
 -n  Don't update file; display results on stdout.
 -b  Use the password from the command line rather than prompting for it.
 -i  Read password from stdin without verification (for script usage).
 -m  Force MD5 encryption of the password (default).
 -B  Force bcrypt encryption of the password (very secure).
 -C  Set the computing time used for the bcrypt algorithm
     (higher is more secure but slower, default: 5, valid: 4 to 17).
 -d  Force CRYPT encryption of the password (8 chars max, insecure).
 -s  Force SHA encryption of the password (insecure).
 -p  Do not encrypt the password (plaintext, insecure).
 -D  Delete the specified user.
 -v  Verify password for the specified user.
On other systems than Windows and NetWare the '-p' flag will probably not work.
The SHA algorithm does not use a salt and is less secure than the MD5 algorithm.

如果没有htpasswd,可以通过安装httpd-tools来安装

sudo yum install httpd-tools

生成.htpasswd文件

htpasswd -c /config/nginx/.htpasswd chq

之后提示输入密码,输入两次密码即可,查看生成的文件:

root@ea6255db9f51:/config/nginx/site-confs# cat /config/nginx/.htpasswd 
chq:$apr1$ixyuvJF1$XQyqpMz96JDYHFWfCqB0U0

可以看到是加密的,修改nginx配置:

server {
    listen 19091 default_server;
    listen [::]:19091 default_server;

    #listen 443 ssl http2 default_server;
    #listen [::]:443 ssl http2 default_server;

    server_name _;

    index index.html index.htm index.php;

    location / {
        # enable for basic auth
        auth_basic "Restricted";
        auth_basic_user_file /config/nginx/.htpasswd;
        proxy_pass http://192.168.2.101:3002;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

这里主要添加了auth_basic和auth_basic_user_file配置

验证效果

之后在浏览器输入网址,重新打开网页,会看到如下提示:

image

输入刚刚设置用户名和密码,进入了网页,说明配置auth_basic成功了。

标签:总结,auth,server,nginx,htpasswd,basic,password
From: https://www.cnblogs.com/chq3272991/p/18499552

相关文章

  • 2024-2025-1 20241401 《计算机基础与程序设计》 第五周学习总结
    班级链接2024计算机基础与程序设计作业要求第五周作业作业目标①Pep/9虚拟机②机器语言与汇编语言③算法与伪代码④测试:黑盒,白盒教材学习内容总结《计算机科学概论》第六章计算机操作:介绍了计算机的基本操作,包括机器语言的基本概念。机器语言是由一系......
  • Nginx的 MIME TYPE问题导致的mjs文件加载出错的问题解决
    .mjs文件:明确表示使用ES6模块系统(ECMAScriptModules)。 在服务器用Nginx部署前端项目后,出现下面这种问题Failedtoloadmodulescript:ExpectedaJavaScriptmodulescriptbuttheserverrespondedwithaMIMEtypeof"application/octet-stream".StrictMIMEt......
  • 考前总结与策略提示
    考前总结与策略提示策略提示放轻松,据以往数据考虑,太紧张会大大降低思考效率不要考虑他人的分数或XXX能不能做出来或没做处理会怎样,考场不是拿来写回忆录的,请珍惜你通过训练换来的考试机会。抄dx的当一个思路的混沌程度/实现难度太高的时候,回溯并重新来如果花费时......
  • nginx 默认60超时需要修改的地址
    1、这个是转发的nginx的vhost模块的php,添加以下代码 ,如果没有,可以忽略location/{if($query_string~*"\.\./|\./"){return404;}proxy_read_timeout300s;#增加到5分钟proxy_connect_timeout300s;prox......
  • 2024/10/23 模拟赛总结
    赛时情况以下是赛时写的。14:10好像当\(n\lem\)时的答案是\(2^n\)。14:20当\(m=2\)时,答案的差值是一个等差数列。答案为\(\dfrac{n(n+1)}{2}+1\)。小样例:\(n=4,m=3\)答案为\(15\)。14:50T1不会啊,润。发现如果你会惹老师生气,干脆直接不写。所以变成了选若干科......
  • https免费nginx证书
    快捷阅读:先安装好nginx,并配置好80端口的正常访问#安装Nginxyuminstall-ynginx#设置开机启动systemctlenablenginx#开启nginxsystemctlstartnginx#重启nginxsystemctlrestartnginx#nginx重新加载配置文件systemctlreloadnginx#新增nginx网站配置......
  • RabbitMQ总结
    重试机制背景线上的系统(SpringBoot2.2.11,rabbitmq为3.2.0),某一天突然有大量的错误日志写入,进几台服务器的硬盘都写满了。查看日志发现是RabbitMQ的消费者在接收消息消费时,抛出了异常错误,此时会不断重新进入消费重新打印错误日志,循环如此进硬盘写满了。RabbitMQ的消息重试机......
  • 2024.10.23总结+CSP2024前总结
    赛时T1看完一脸懵逼啊,画了好几个立方体,一直觉得切四刀是14块,然后也找不到什么规律,就去看后面的题了,jsy说是15之后还是没想法,只觉着\(7=2^3-1\),\(15=2^4-1\),当\(n<=m\)时是\(2^n\),后来看回来把已知情况全列出来,找到\(f[i][j]=f[i][j-1]+f[i-1][j-1]\)的递推式,写了60pts的,但WA了......
  • centos7 nginx优化
    优化nginx进程个数的策略在高并发、高访问量的web服务场景,需要事先启动好更多的nginx进程,以保证快速响应并处理大量并发用户的请求。worker_processes1;一般调整到与CPU的颗数相同查看LInux可查看CPU个数及总核数grepprocessor/proc/cpuinfo|wc-l优化绑定不同......
  • Springboot知识点总结
    一、传统使用配置文件方式创建Java对象:1、创建一个普通的Maven项目,并加入依赖:<dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.3.1</version></dependency>&......