小知识:Nginx服务器中浏览器本地缓存和虚拟机的相关设置

自动列出目录配置:

下载过开源软件的都知道,一个很简单的页面列出了所有版本的源码包,这就是开启了自动列出目录

如下配置,在虚拟主机location / {……}目录控制中配置自动列出目录:

 
?
1
2
3
autoindex on;
}

浏览器本地缓存设置:

浏览器是为了加速浏览,浏览器在用户磁盘上对最近请求过的文件进行存储,当访问者再次请求这个页面,

浏览器可以从本地磁盘显示文件,以达到加速浏览的效果,节约了网络资源,提高了网络效率

关键字: expires

默认值: off

作用域: http,server.location

用途: 通过expires指令控制http应答中的”Expires”和”Cache-Control”的头信息

配置项:

?
1
2
3
4
5
6
7
8
9
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}

配置虚拟主机:

  nginx可以配置多种类型的虚拟主机,基于ip的 基于域名的 基于端口的,

简单一句话说就是不同ip相同端口,不同端口相同ip or域名,不同域名相同端口

下面是基于相同域名的虚拟主机配置文件:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
server {
listen  80 default;
server_name www.wpython.com;
index index.html index.htm index.php;
root /alidata/www/www.wpython.com;
# wordpress 伪静态规则
location / {
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~ .*\.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
access_log /alidata/log/nginx/access/www.wpython.com.log;
}
server {
listen  80 default;
server_name www.pyyw.net;
index index.html index.htm index.php;
root /alidata/www/www.pyyw.net;
# wordpress 伪静态规则
location / {
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~ .*\.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
access_log /alidata/log/nginx/access/www.pyyw.net.log;
}
声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:Linux 内核如何处理中断

2023-5-4 2:54:24

建站知识

小知识:运维监控系统之Prometheus Server安装

2023-5-4 3:02:50

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索