当前位置: 首页 > news >正文

Nginx使用—基础应用

Nginx日志配置

1.mkdir /etc/nginx/logs2.server{listen 80;server_name nrj.test.com;access_log logs/acess-test.log; #正确日志error_log  logs/error-test.log; #错误日志root /www;index index.html;
}

Nginx目录索引

语法:autoindex on | off
默认:autoindex off;
使用模块:hhttp,server,location#autoindex常用参数
autoindex_exact_size off;
默认为on,显示出文字的确切大小,单位是bytes
修改为off,显示出文字的大概大小,单位是kb或者mb或者gbautoindex_localtime on;
默认为off,显示文件时间为GMT时间
修改为on ,显示的文件时间为文件的服务器时间charset utf-8,gbk;
默认中文目录乱码,添加上解决乱码。
vim /etc/nginx/conf.d/download.conf
server{listen 80;server_name download.nrj.com; autoindex on; #是否开启autoindex_exact_size off; #是否显示大小autoindex_localtime on; #文件时间charset utf-8; #字符集root /www/download;index index.html; 
}

Nginx状态监控

server{listen 80;server_name nrj.maliao.com;location / {root /www/maliao;index index.html;}location /stub_status {  stub_status on; access_log off;}
}基于ip地址访问控制
server{listen 80;server_name nrj.maliao.com;location / {root /www/maliao;index index.html;}location /stub_status {  stub_status on;access_log off;allow 10.0.0.1; #允许allow 127.0.0.1; deny all; #不允许}
}

Nginx访问控制

基于用户登录的认证
#配置语法
语法: auth_basic string| off;
默认: auth_basic off;
应用模块:http,server,location,limit_except
#用户密码记录配置文件
语法: auth_basic_user_file file;
默认: -
应用模块: http,server,location,limit_excepthttpd-tools
yum install -y httpd-tools
htpasswd -b -c /etc/nginx/auth_conf nrj 123
server{listen 80;server_name nrj.maliao.com;location / {root /www/maliao;index index.html;auth_basic on;auth_basic_user_file auth_conf;}location /stub_status {  stub_status on;access_log off;allow 10.0.0.1;allow 127.0.0.1;deny all;}
}

Nginx虚拟站点

1.基于不同的端口号
vim /etc/nginx/conf.d/test.conf
server{listen 80;server_name localhost;root /www/test;index index.html;
}
server{listen 81;server_name localhost;root /www/test;index index.html;
}2.基于不同的域名
vim /etc/nginx/conf.d/test.conf
server{listen 80;server_name maliao.com;root /www/test;index index.html;
}
server{listen 80;server_name test.maliao.com;root /www/test;index index.html;
}
server{listen 80;server_name abc.maliao.com;root /www/test;index index.html;
}3.基于域名的别名
vim /etc/nginx/conf.d/test.conf
server{listen 80;server_name www.maliao.com maliao.com;root /www/test;index index.html;
}

案例练习

部署nginx web server,要求如下:

1)部署三个站点,需要通过域名访问,有独立的日志 h5game.zjh.com donwload.zjh.com maliao.zjh.com

2)要求每个站点都开启状态监控

3)download开启目录索引

4)download需要通过用户认证才能访问

5)每个站点的状态监控只允许10.0.0.1可以访问  

环境准备
1.准备游戏压缩包
[root@web03 ~]# ls 
anaconda-ks.cfg  h5game.zip  html5-mario.zip2.创建/web目录存放相关文件
mkdir -p /web3.将压缩包解压后移动至/web目录下并在/web目录下创建download目录
unzip h5game.zip 
unzip html5-mario.zip 
mv h5game /web
mv html5-mario /web/maliao
mkdir -p /web/download4.向download目录下放置点资源
cd /web/download5.配置用户认证
htpasswd -bc /etc/nginx/auth_conf zjh 1236.创建独立日志文件目录
mkdir /etc/nginx/logs编写配置文件
1.编写配置文件,将三个虚拟站点写在一起
vim /etc/nginx/conf.d/default.conf
server {listen 80;server_name h5game.zjh.com;access_log logs/acess-h5game.log;error_log  logs/error-h5game.log;location /{root /web/h5game;index index.html; }	location /stub_status {  stub_status on;access_log off;allow 10.0.0.1;deny all;}
}
server {listen 80;server_name download.zjh.com;access_log logs/acess-download.log;error_log  logs/error-download.log;location /{auth_basic on;auth_basic_user_file auth_conf;autoindex on;autoindex_exact_size off;autoindex_localtime on;charset utf-8;root /web/download;index index.html;}location /stub_status {  stub_status on;access_log off;allow 10.0.0.1;deny all;}
}
server {listen 80;server_name maliao.zjh.com;access_log logs/acess-maliao.log;error_log  logs/error-maliao.log;location /{root /web/maliao;index index.html; }	location /stub_status {  stub_status on;access_log off;allow 10.0.0.1;deny all;}
}

 

相关文章:

  • 图像处理与视觉感知---期末复习重点(1)
  • 如何在Spring Boot框架中打印响应的日志?
  • 【Mining Data】收集数据(使用 Python 挖掘 Twitter 数据)
  • js如何渲染页面
  • [渗透教程]-024-Hashcat密码破解
  • LLM(十一)| Claude 3:Anthropic发布最新超越GPT-4大模型
  • Python 开发图形界面程序
  • 二十五、剖析HashMap
  • 《javascript高级程序设计》学习笔记 | 23.JSON
  • 2024年JSON 面试题目-1
  • LeetCode刷题---填充每个节点的下一个右侧节点指针
  • Linux设置静态IP地址
  • 10个常见的Java面试问题及其答案
  • 口碑营销:品牌如何维护良好口碑?
  • 就业班 2401--3.6 Linux Day12--计划任务和邮件和ssh远程连接
  • 【Leetcode】101. 对称二叉树
  • JavaScript DOM 10 - 滚动
  • Lsb图片隐写
  • Node.js 新计划:使用 V8 snapshot 将启动速度提升 8 倍
  • Python学习之路13-记分
  • SpringBoot几种定时任务的实现方式
  • Webpack 4 学习01(基础配置)
  • 精彩代码 vue.js
  • 聊聊flink的TableFactory
  • 前端自动化解决方案
  • 什么软件可以提取视频中的音频制作成手机铃声
  • 【运维趟坑回忆录】vpc迁移 - 吃螃蟹之路
  • ​软考-高级-系统架构设计师教程(清华第2版)【第9章 软件可靠性基础知识(P320~344)-思维导图】​
  • ![CDATA[ ]] 是什么东东
  • $ git push -u origin master 推送到远程库出错
  • $$$$GB2312-80区位编码表$$$$
  • (07)Hive——窗口函数详解
  • (12)Hive调优——count distinct去重优化
  • (16)Reactor的测试——响应式Spring的道法术器
  • (33)STM32——485实验笔记
  • (Redis使用系列) Springboot 在redis中使用BloomFilter布隆过滤器机制 六
  • (二) Windows 下 Sublime Text 3 安装离线插件 Anaconda
  • (二)c52学习之旅-简单了解单片机
  • (附源码)spring boot智能服药提醒app 毕业设计 102151
  • (附源码)springboot炼糖厂地磅全自动控制系统 毕业设计 341357
  • (学习日记)2024.03.12:UCOSIII第十四节:时基列表
  • (源码版)2024美国大学生数学建模E题财产保险的可持续模型详解思路+具体代码季节性时序预测SARIMA天气预测建模
  • (转)从零实现3D图像引擎:(8)参数化直线与3D平面函数库
  • (转)四层和七层负载均衡的区别
  • (转载)利用webkit抓取动态网页和链接
  • .net core 微服务_.NET Core 3.0中用 Code-First 方式创建 gRPC 服务与客户端
  • .Net Core 中间件验签
  • .NET 使用 XPath 来读写 XML 文件
  • .NET/C# 异常处理:写一个空的 try 块代码,而把重要代码写到 finally 中(Constrained Execution Regions)
  • @Bean有哪些属性
  • @Bean注解详解
  • [120_移动开发Android]008_android开发之Pull操作xml文件
  • [⑧ADRV902x]: Digital Pre-Distortion (DPD)学习笔记
  • [BZOJ1877][SDOI2009]晨跑[最大流+费用流]
  • [c#基础]DataTable的Select方法