使用Nginx缓存网页
2016-05-03 22:22
706 查看
这几天尝试使用Nginx服务器,查看了该服务器的用途。发现该服务器可以用来实现反向代理和负载均衡等功能,自己通过查找资料实现了缓存网页的功能,下面是我的Nginx的配置文件的设置,配置文件的路径为:/usr/local/nginx/conf/nginx.conf
下面有两篇关于nginx.conf的详细介绍:
nginx.conf的完整配置说明
Nginx安装及配置文件nginx.conf详解
Nginx Location 配置总结
nginx的基本配置和虚拟主机的配置
nginx主配置文件详解
使用nginx的proxy_cache做网站缓存
nginx缓存功能的设置
Nginx配置文件nginx.conf中文详解
以下是我的nginx.conf的文件内容:
在重新载入上述修改之后的文件之前,先在/usr/local/nginx中创建一个wenserver文件夹:
然后运行如下命令:
然后在浏览器中输入Nginx的IP地址和端口号即可,访问网页。
下面有两篇关于nginx.conf的详细介绍:
nginx.conf的完整配置说明
Nginx安装及配置文件nginx.conf详解
Nginx Location 配置总结
nginx的基本配置和虚拟主机的配置
nginx主配置文件详解
使用nginx的proxy_cache做网站缓存
nginx缓存功能的设置
Nginx配置文件nginx.conf中文详解
以下是我的nginx.conf的文件内容:
#用户组 用户 #user nobody; #工作进程,根据硬件调整 worker_processes 1; #错误日志 #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid文件位置 #pid logs/nginx.pid; events { #工作进程的最大连接数 worker_connections 1024; } http { #设定mime类型 include mime.types; #默认文件类型 default_type application/octet-stream; #日志格式 #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #访问日志 #access_log logs/access.log main; #开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件, #对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off, #以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off。 sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; #设置缓存路径和名称为webserver,内存缓存空间大小为200MB,30天没有被访问的内容自动清除,硬盘缓存空间大小为30GB。 proxy_cache_path /usr/local/nginx/webserver levels=1:2 keys_zone=webserver:200m inactive=3d max_size=30g; server { #指定虚拟主机的服务端口 listen 1025; #制定虚拟主机的IP地址 server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #自定义响应首部 #添加一个X-Via显示服务器地址 add_header X-Via $server_addr; #添加一个X-Cache显示缓存是否命中 add_header X-Cache $upstream_cache_status; location / { #root指令用于指定虚拟主机的网页根目录,这个目录可以是相对路径,也可以是绝对路径 root html; #index用于设定访问的默认首页地址 index index.html index.htm; #设置转发的目的路径即被代理服务器的地址 proxy_pass http://www.jlu.edu.cn; #设置缓冲区的名字 proxy_cache webserver; #为不同应答设置缓存时间 proxy_cache_valid 200 10m; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html #设置当出现错误的时候跳转的页面 error_page 500 502 503 504 /50x.html; location = /50x.html { root html; proxy_pass http://www.jlu.edu.cn; proxy_cache webserver; proxy_cache_valid 200 10m; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
在重新载入上述修改之后的文件之前,先在/usr/local/nginx中创建一个wenserver文件夹:
mkdir webserver
然后运行如下命令:
./nginx -s reload
然后在浏览器中输入Nginx的IP地址和端口号即可,访问网页。
相关文章推荐
- nginx代理指定目录
- 访问Nginx发生SSL connection error的一种情况
- Nginx+Naxsi部署专业级Web应用防火墙
- CentOS 6.2实战部署Nginx+MySQL+PHP
- nginx中http核心模块的配置指令2
- nginx中http核心模块的配置指令3
- nginx中http核心模块的配置指令4
- nginx中http的fastcgi模块的配置指令1
- Nginx 学习笔记(一)
- 网站502与504错误分析
- 用zabbix监控nginx_status状态
- 艰难完成 nginx + puma 部署 rails 4的详细记录
- 把Lua编译进nginx步骤方法
- 浅析SQL Server中的执行计划缓存(上)
- Enterprise Library for .NET Framework 2.0缓存使用实例
- PowerShell中编程清空IE缓存方法
- PowerShell中使用.NET将程序集加入全局程序集缓存
- C#中缓存的基本用法总结
- web 应用中常用的各种 cache详解