[root@localhost server]#vim /apps/nginx/conf/server/www_magedu_net.conf
# auth_basic "login password"; 把登录模块注释下
# auth_basic_user_file /apps/nginx/.htpassword;
[root@localhost server]#nginx -s reload 重新加载服务
访问页面
[root@localhost pc]#vim /data/nginx/html/pc/default.html 创建默认页面
default page
[root@localhost server]#vim www_magedu_net.conf
location /login {
root /data/nginx/html/pc;
index index.html;
# auth_basic "login password";
# auth_basic_user_file /apps/nginx/.htpassword;
try_files $uri /default.html; 如果这个页面不存在就进入到这个默认的页面。
}
[root@localhost server]#nginx -s reload 加载服务
访问不存在的页面就会进入到这个默认的页面
[root@localhost server]#vim www_magedu_net.conf
try_files $uri /linux/36/default.html $uri/index.html $uri.html 修改成错误的路径
/about/default.html;
# try_files $uri /linux/36/default.html $uri/index.html $uri.html /about/default.html;
try_files $uri $uri/index.html $uri.html =666; 找不到这些自动补充的页面,就出现状态码666
[root@localhost server]#nginx -s reload
这个就是状态码666
[root@client ~]#vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.22.90.10 www.magedu.net
这种开发和测试用的特别多
写入本地hosts,指定公司的某个域名
访问的出现错误了,这个是判断用户访问的uri是否存在
[root@localhost conf]#vim nginx.conf
keepalive_requests 3; 把这个值改成3次 ,这个连接如果超过3次就需要重新连接
[root@localhost conf]#nginx -s reload
[root@client yum.repos.d]#yum install telnet -y 安装telenet
访问三次就失败了[root@client yum.repos.d]#telnet www.magedu.net 80
,断开之后就需要刷新页面了
[root@localhost server]#vim /apps/nginx/conf/server/www_magedu_net.conf
location /download { 创建这个文件夹
index index.html;
root /data/nginx/html/pc; 路径在这里
}
}
[root@localhost server]#mkdir /data/nginx/html/pc/download创建文件夹,用来存放文件
[root@localhost server]#cp /root/anaconda-ks.cfg /data/nginx/html/pc/download 拷贝文件过去
[root@localhost server]#cd /data/nginx/html/pc/download
[root@localhost download]#vim /apps/nginx/conf/server/www_magedu_net.conf
location /download {
index index.html;
root /data/nginx/html/pc;
autoindex on; 增加索引功能
autoindex_exact_size on; 可以查看文件大小
autoindex_localtime on; 可以查看本地时间
}
[root@localhost download]#nginx -s reload
现在就可以访问了
[root@localhost download]#vim /apps/nginx/conf/server/www_magedu_net.conf
autoindex_exact_size off; 这个就是修改成多少mb
limit_rate 10k; 这个是限速
[root@localhost download]#nginx -s reload
限速10kb每秒
[root@localhost /]#vim /apps/nginx/conf/nginx.conf
#keepalive_timeout 0;
keepalive_timeout 65 60;
keepalive_requests 3;
client_max_body_size 10m; 设置客户端上传单个文件的最大值
client_body_buffer_size 16k; 用于接收每个客户端请求报文的body
client_body_temp_path /apps/nginx/temp 1 2 2; 这个是上传到那个文件夹自动创建#设定存储客户端请求报文的body部分的临时存储路径及子目录结构和数量,目录名为16进制的数字,使用hash
之后的值从后往前截取1位、2位、2位作为文件名:
[root@localhost nginx]#mkdir /data/nginx/html/pc/upload 创建这个上传的文件夹
[root@localhost nginx]#nginx -s reload
客户端
[root@localhost /]#vim /apps/nginx/conf/nginx.conf
keepalive_disable msie6; #对哪种浏览器禁用长连接ie的浏览器
[root@localhost /]#nginx -s reload
[root@client data]#curl --head www.magedu.net 查看访问的头部
HTTP/1.1 200 OK 查看状态码200
Server: nginx/1.14.2 查看服务器的信息
Date: Thu, 30 May 2019 11:04:56 GMT 时间
Content-Type: text/html 什么类型的页面
Content-Length: 3
Last-Modified: Wed, 29 May 2019 14:21:22 GMT
Connection: keep-alive
Keep-Alive: timeout=60
ETag: "5cee9562-3" cdn 缓存访问加速
Accept-Ranges: bytes
[root@localhost server]#cd /apps/nginx/conf/server
[root@localhost server]#vim www_magedu_net.conf
location /upload {
root /data/nginx/html/pc;
limit_except GET { 排除get以外的方式的访问
allow 172.20.90.7; 只允许这个ip地访问
deny all; 其他的都拒绝
}
}
}
[root@localhost server]#nginx -s reload
[root@client data]#curl -XPUT /etc/issue http://www.magedu.net/upload 这个一般配置在防火墙里,不在这里配置
curl: (3) <url> malformed
<html>
<head><title>405 Not Allowed</title></head> 405表示没有这个功能
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/1.14.2</center>
</body>
</html>
[root@localhost conf]#vim nginx.conf
directio 2m; 一旦超过2mb,就直接写入磁盘,不经过缓存
[root@localhost conf]#nginx -s reload
[root@localhost conf]#vim nginx.conf
open_file_cache max=10000 inactive=20s;超过20秒不在缓存了
open_file_cache_valid 30s; 每隔30秒检查文件是否可用
open_file_cache_min_uses 2; 30秒内至少被访问2次
open_file_cache_errors on; 缓存错误信息
nginx的并发1两千,可用不用陪,达到上万就需要配了,缓存能看到效果
[root@localhost conf]#nginx -s reload
[root@localhost conf]#vim nginx.conf
server_tokens off; 关闭版本号 ,相应的提高安全性
[root@localhost conf]#nginx -s reload
这个就没有版本号了