5-Ngnix配置基于用户访问控制和IP的虚拟主机
目录
5.1.Ngnix配置基于用户访问控制的多虚拟主机
5.1.1.前提条件
5.1.2.Ngnix配置基于用户访问控制的多虚拟主机
5.2.Ngnix配置基于IP的虚拟主机
5.3.Ngnix配置基于IP的多虚拟主机
Nginx配置文件在/usr/local/nginx/conf下,文件名为nginx.conf
5.1.Ngnix配置基于用户访问控制的多虚拟主机
5.1.1.前提条件
Ngnix配置基于用户访问控制的多虚拟主机时,需要使用htpasswd命令,需要安装httpd-tools rpm
命令:
yum install -y httpd-tools
[root@cent79-2 ~]# yum install -y httpd-tools
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile* base: mirrors.aliyun.com* centos-sclo-rh: mirrors.huaweicloud.com* centos-sclo-sclo: mirrors.huaweicloud.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.4.6-99.el7.centos.1 will be installed
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-tools-2.4.6-99.el7.centos.1.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-tools-2.4.6-99.el7.centos.1.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-7.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7_9.1 will be installed
--> Finished Dependency ResolutionDependencies Resolved=============================================================================================================Package Arch Version Repository Size
=============================================================================================================
Installing:httpd-tools x86_64 2.4.6-99.el7.centos.1 updates 94 k
Installing for dependencies:apr x86_64 1.4.8-7.el7 CentOS7 104 kapr-util x86_64 1.5.2-6.el7_9.1 updates 92 kTransaction Summary
=============================================================================================================
Install 1 Package (+2 Dependent packages)Total download size: 290 k
Installed size: 584 k
Downloading packages:
(1/2): apr-util-1.5.2-6.el7_9.1.x86_64.rpm | 92 kB 00:00:00
(2/2): httpd-tools-2.4.6-99.el7.centos.1.x86_64.rpm | 94 kB 00:00:00
-------------------------------------------------------------------------------------------------------------
Total 356 kB/s | 290 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transactionInstalling : apr-1.4.8-7.el7.x86_64 1/3 Installing : apr-util-1.5.2-6.el7_9.1.x86_64 2/3 Installing : httpd-tools-2.4.6-99.el7.centos.1.x86_64 3/3 Verifying : apr-util-1.5.2-6.el7_9.1.x86_64 1/3 Verifying : apr-1.4.8-7.el7.x86_64 2/3 Verifying : httpd-tools-2.4.6-99.el7.centos.1.x86_64 3/3 Installed:httpd-tools.x86_64 0:2.4.6-99.el7.centos.1 Dependency Installed:apr.x86_64 0:1.4.8-7.el7 apr-util.x86_64 0:1.5.2-6.el7_9.1 Complete!
[root@cent79-2 ~]#
5.1.2.Ngnix配置基于用户访问控制的多虚拟主机
-->进入/usr/local/nginx/conf目录
命令:
cd /usr/local/nginx/conf
pwd
[root@cent79-2 conf]# cd /usr/local/nginx/conf/
[root@cent79-2 conf]# pwd
/usr/local/nginx/conf
[root@cent79-2 conf]#
-->编辑nginx.conf,并保存
命令:
vi nginx.conf

--> 验证nginx.conf语法的正确性
命令:
nginx -t
[root@cent79-2 conf]# nginx -t
nginx: the configuration file /usr/local/nginx//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx//conf/nginx.conf test is successful
[root@cent79-2 conf]#
-->创建用户访问控制文件
命令:
htpasswd -c /usr/local/nginx/conf/nginxpasswd ztj
[root@cent79-2 conf]# htpasswd -c /usr/local/nginx/conf/nginxpasswd ztj
New password:
Re-type new password:
Adding password for user ztj
[root@cent79-2 conf]# cat /usr/local/nginx/conf/nginxpasswd
ztj:$apr1$bKLsHgJ3$X8j4Buj2KCw4ojcm3HuTX1
[root@cent79-2 conf]#
备注:
如果创建多个用户访问控制时,后续命令为:
htpasswd /usr/local/nginx/conf/nginxpasswd USERNAME
-->重启nginx
命令:
nginx -s stop
nginx
[root@cent79-2 conf]# nginx -s stop
[root@cent79-2 conf]# ps -ef |grep nginx
root 1354 1245 0 15:39 pts/0 00:00:00 grep --color=auto nginx
[root@cent79-2 conf]# nginx
[root@cent79-2 conf]# ps -ef |grep nginx
root 1356 1 0 15:39 ? 00:00:00 nginx: master process nginx
nginx 1357 1356 0 15:39 ? 00:00:00 nginx: worker process
root 1359 1245 0 15:40 pts/0 00:00:00 grep --color=auto nginx
[root@cent79-2 conf]#
-->验证
http://www.itztj.com

输入通过htpasswd命令创建的用户控制文件的用户名和密码

http://www.itxiaohei.com

输入通过htpasswd命令创建的用户控制文件的用户名和密码

5.2.Ngnix配置基于IP的虚拟主机
-->进入/usr/local/nginx/conf目录
命令:
cd /usr/local/nginx/conf
pwd
[root@cent79-2 conf]# cd /usr/local/nginx/conf/
[root@cent79-2 conf]# pwd
/usr/local/nginx/conf
[root@cent79-2 conf]#
-->编辑nginx.conf,并保存
命令:
vi nginx.conf

--> 验证nginx.conf语法的正确性
命令:
nginx -t
[root@cent79-2 conf]# nginx -t
nginx: the configuration file /usr/local/nginx//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx//conf/nginx.conf test is successful
[root@cent79-2 conf]#
-->重新加载nginx
命令:
nginx -s reload
[root@cent79-2 conf]# nginx -s reload
[root@cent79-2 conf]# ps -ef |grep nginx
root 1591 1 0 16:04 ? 00:00:00 nginx: master process nginx
nginx 1594 1591 0 16:04 ? 00:00:00 nginx: worker process
root 1596 1182 0 16:05 pts/0 00:00:00 grep --color=auto nginx
[root@cent79-2 conf]#
-->验证
curl 192.168.10.156
[root@cent79-2 conf]# curl 192.168.10.156
I am itztj
[root@cent79-2 conf]#
宿主机验证

5.3.Ngnix配置基于IP的多虚拟主机
-->进入/usr/local/nginx/conf目录
命令:
cd /usr/local/nginx/conf
pwd
[root@cent79-2 conf]# cd /usr/local/nginx/conf/
[root@cent79-2 conf]# pwd
/usr/local/nginx/conf
[root@cent79-2 conf]#
-->编辑nginx.conf,并保存
命令:
vi nginx.conf

--> 验证nginx.conf语法的正确性
命令:
nginx -t
[root@cent79-2 conf]# nginx -t
nginx: the configuration file /usr/local/nginx//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx//conf/nginx.conf test is successful
[root@cent79-2 conf]#
-->重新加载nginx
命令:
nginx -s reload
[root@cent79-2 conf]# nginx -s reload
[root@cent79-2 conf]# ps -ef |grep nginx
root 1591 1 0 16:04 ? 00:00:00 nginx: master process nginx
nginx 1594 1591 0 16:04 ? 00:00:00 nginx: worker process
root 1596 1182 0 16:05 pts/0 00:00:00 grep --color=auto nginx
[root@cent79-2 conf]#
-->验证


相关文章:
5-Ngnix配置基于用户访问控制和IP的虚拟主机
目录 5.1.Ngnix配置基于用户访问控制的多虚拟主机 5.1.1.前提条件 5.1.2.Ngnix配置基于用户访问控制的多虚拟主机 5.2.Ngnix配置基于IP的虚拟主机 5.3.Ngnix配置基于IP的多虚拟主机 Nginx配置文件在/usr/local/nginx/conf下,文件名为nginx.conf 5.1.Ngnix配置…...
springboot jar分离部署
springboot jar分离部署 注意:spring boot web项目别使用jsp页面,可以使用模板代替,jsp打包时访问页面会报404错误。 1.具体配置如下: <build><plugins><!--更换maven的jar打包插件先前使用的是spring-boot-mav…...
Opencv 细节补充
1.分辨率的解释 •像素:像素是分辨率的单位。像素是构成位图图像最基本的单元,每个像素都有自己的颜色。 •分辨率(解析度): a) 图像分辨率就是单位英寸内的像素点数。单位为PPI(Pixels Per Inch) b) PPI表示的是每英…...
内存泄漏专题(7)hook之宏定义
前面介绍的mtrace也好,bcc也罢,其实都是hook技术的一种实现,但是mtrace本身使用场景上有局限,而bcc环境依赖则十分复杂。因此,这些调试手段只适用于开发环境用来调试,对于生产环境,均不是一个非…...
Python 基础(十八):异常处理
❤️ 博客主页:水滴技术 🌸 订阅专栏:Python 入门核心技术 🚀 支持水滴:点赞👍 收藏⭐ 留言💬 文章目录 一、异常是什么?二、异常处理的基本语法三、捕获特定的异常类型四、finall…...
iTOP-RK3568开发板Docker 安装 Ubuntu 18.04
Docker 下载安装 Ubuntu18.04,输入以下命令: sudo apt update docker pull ubuntu:18.04 切换 Shell 到 Ubuntu 18.04,输入以下命令: docker container run -p 8000:3000 -it ubuntu:18.04 /bin/bash -p 参数:容器的…...
FFmpeg AVFilter的原理(三)- filter是如何被驱动的
首先上官方filter的链接:https://ffmpeg.org/ffmpeg-filters.html 关于filter命令行:FFmpeg-4.0 的filter机制的架构与实现.之一 Filter原理 1、下面是一个avfilter的graph 上图是ffmpeg中doc/examples中filtering_video.c案例的示意图。 特别注意上面蓝…...
ARM day8 key1/2/3led
key_led.h #ifndef _KEY_H_ #define _KEY_H_#include "stm32mp1xx_rcc.h" #include "stm32mp1xx_gpio.h" #include "stm32mp1xx_exti.h" #include "stm32mp1xx_gic.h"//EXTI编号 typedef enum {EXTI0,EXTI1,EXTI2,EXTI3,EXTI4,EXTI5,…...
windows 系统安装sonarqube
SonarQube是一种自动代码审查工具,用于检测代码中的错误,漏洞和代码异味。它可以与您现有的工作流程集成,以便在项目分支和拉取请求之间进行连续的代码检查。 官方网站: https://www.sonarqube.org/ 1. 使用前提条件 运行SonarQ…...
Unity噪声图生成(编辑器扩展)
最近发现项目里很多shader都需要噪声图,(shadergraph中有自己的噪声图生成)当遇到需要噪声图时去寻找很麻烦,所以从网上查阅资料编写了一个Unity扩展的噪声图生成。 Perlin噪声 Perlin噪声是一种渐变噪声算法,由Ken …...
http-为什么文件上传要转成Base64
# 前言 最近在开发中遇到文件上传采用Base64的方式上传,记得以前刚开始学http上传文件的时候,都是通过content-type为multipart/form-data方式直接上传二进制文件,我们知道都通过网络传输最终只能传输二进制流,所以毫无疑问他们本…...
htmlCSS-----定位
目录 前言 定位 分类和取值 定位的取值 1.相对定位 2.绝对位置 元素居中操作 3.固定定位 前言 今天我们来学习html&CSS中的元素的定位,通过元素的定位我们可以去更好的将盒子放到我们想要的位置,下面就一起来看看吧! 定位 定位posi…...
腾讯云大数据型CVM服务器实例D3和D2处理器CPU型号说明
腾讯云服务器CVM大数据型D3和D2处理器型号,大数据型D3云服务器CPU采用2.5GHz Intel Xeon Cascade Lake 处理器,大数据型D2云服务器CPU采用2.4GHz Intel Xeon Skylake 6148 处理器。腾讯云服务器网分享云服务器CVM大数据型CPU型号、处理器主频性能&#x…...
计算机科学cs/电子信息ei面试准备——数学基础/线性代数复习
1. 中值定理 中值定理是反映函数与导数之间联系的重要定理,也是微积分学的理论基础,在许多方面它都有重要的作用,在进行一些公式推导与定理证明中都有很多应用。中值定理是由众多定理共同构建的,其中拉格朗日中值定理是核心&…...
极速查找(2)-算法分析
篇前小言 本篇文章是对查找(1)的续讲线性索引查找 线性索引查找(Linear Index Search)是一种基于索引的查找算法。它在数据集合中创建一个索引 结构,然后使用该索引结构来加快对目标元素的查找。 线性索引是一种在数…...
flask路由添加参数
flask路由添加参数 在 Flask 中,可以通过两种方式在路由中添加参数:在路由字符串中直接指定参数,或者通过 request 对象从请求中获取参数。 在路由字符串中指定参数:可以将参数直接包含在路由字符串中。参数可以是字符串、整数、…...
网络安全系统教程+学习路线(自学笔记)
一、什么是网络安全 网络安全可以基于攻击和防御视角来分类,我们经常听到的 “红队”、“渗透测试” 等就是研究攻击技术,而“蓝队”、“安全运营”、“安全运维”则研究防御技术。 无论网络、Web、移动、桌面、云等哪个领域,都有攻与防两面…...
23. 合并 K 个升序链表
题目描述 给你一个链表数组,每个链表都已经按升序排列。 请你将所有链表合并到一个升序链表中,返回合并后的链表。 示例 1: 输入:lists [[1,4,5],[1,3,4],[2,6]] 输出:[1,1,2,3,4,4,5,6] 解释:链表数组…...
Nexus3部署、配置+SpringBoot项目Demo
Docker部署Nexus 搜索Nexus3镜像:[rootlocalhost ~]# docker search nexus 拉取Nexus3镜像:[rootlocalhost ~]# docker pull sonatype/nexus3 启动Nexus3前查看虚拟机端口是否被占用:[rootlocalhost ~]# netstat -nultp 通过Docker Hub查看安…...
linux下用docker安装mysql
1.mysql Docker镜像 docker pull mysql:[版本号 或 latest]例:docker pull mysql:5.7 2.查看拉取的docker镜像 docker images3.设置 Docker 卷 docker volume create mysql-data列出 Docker 已知的所有卷 docker volume ls4.运行一个 MySQL Docker 容器 docke…...
wordpress后台更新后 前端没变化的解决方法
使用siteground主机的wordpress网站,会出现更新了网站内容和修改了php模板文件、js文件、css文件、图片文件后,网站没有变化的情况。 不熟悉siteground主机的新手,遇到这个问题,就很抓狂,明明是哪都没操作错误&#x…...
智慧医疗能源事业线深度画像分析(上)
引言 医疗行业作为现代社会的关键基础设施,其能源消耗与环境影响正日益受到关注。随着全球"双碳"目标的推进和可持续发展理念的深入,智慧医疗能源事业线应运而生,致力于通过创新技术与管理方案,重构医疗领域的能源使用模式。这一事业线融合了能源管理、可持续发…...
利用ngx_stream_return_module构建简易 TCP/UDP 响应网关
一、模块概述 ngx_stream_return_module 提供了一个极简的指令: return <value>;在收到客户端连接后,立即将 <value> 写回并关闭连接。<value> 支持内嵌文本和内置变量(如 $time_iso8601、$remote_addr 等)&a…...
Leetcode 3576. Transform Array to All Equal Elements
Leetcode 3576. Transform Array to All Equal Elements 1. 解题思路2. 代码实现 题目链接:3576. Transform Array to All Equal Elements 1. 解题思路 这一题思路上就是分别考察一下是否能将其转化为全1或者全-1数组即可。 至于每一种情况是否可以达到…...
FFmpeg 低延迟同屏方案
引言 在实时互动需求激增的当下,无论是在线教育中的师生同屏演示、远程办公的屏幕共享协作,还是游戏直播的画面实时传输,低延迟同屏已成为保障用户体验的核心指标。FFmpeg 作为一款功能强大的多媒体框架,凭借其灵活的编解码、数据…...
【Linux】C语言执行shell指令
在C语言中执行Shell指令 在C语言中,有几种方法可以执行Shell指令: 1. 使用system()函数 这是最简单的方法,包含在stdlib.h头文件中: #include <stdlib.h>int main() {system("ls -l"); // 执行ls -l命令retu…...
376. Wiggle Subsequence
376. Wiggle Subsequence 代码 class Solution { public:int wiggleMaxLength(vector<int>& nums) {int n nums.size();int res 1;int prediff 0;int curdiff 0;for(int i 0;i < n-1;i){curdiff nums[i1] - nums[i];if( (prediff > 0 && curdif…...
如何将联系人从 iPhone 转移到 Android
从 iPhone 换到 Android 手机时,你可能需要保留重要的数据,例如通讯录。好在,将通讯录从 iPhone 转移到 Android 手机非常简单,你可以从本文中学习 6 种可靠的方法,确保随时保持连接,不错过任何信息。 第 1…...
【单片机期末】单片机系统设计
主要内容:系统状态机,系统时基,系统需求分析,系统构建,系统状态流图 一、题目要求 二、绘制系统状态流图 题目:根据上述描述绘制系统状态流图,注明状态转移条件及方向。 三、利用定时器产生时…...
微服务商城-商品微服务
数据表 CREATE TABLE product (id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 商品id,cateid smallint(6) UNSIGNED NOT NULL DEFAULT 0 COMMENT 类别Id,name varchar(100) NOT NULL DEFAULT COMMENT 商品名称,subtitle varchar(200) NOT NULL DEFAULT COMMENT 商…...
