行业知识
Nginx使用—基础应用
2026-11-08 06:41:26
来源:互联网转载
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.confserver{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-toolsyum install -y httpd-toolshtpasswd -b -c /etc/nginx/auth_conf nrj 123server{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.confserver{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.confserver{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.confserver{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 /webmv html5-mario /web/maliaomkdir -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.confserver { 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;}}
上一篇:怎么在服务器上搭建论坛?
下一篇:上来哪里英语怎么说?