发布于 2016-02-08 03:57:42 | 107 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Nginx中文文档,程序狗速度看过来!

Nginx WEB服务器

Nginx 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。


这篇文章主要介绍了Nginx服务器中浏览器本地缓存和虚拟机的相关设置,是Nginx服务器搭建过程中的基本配置,需要的朋友可以参考下

自动列出目录配置:

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

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


location / {
  autoindex on;
}

浏览器本地缓存设置:

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

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

关键字: expires

默认值: off

作用域: http,server.location

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

配置项:

 


location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires 30d;
    }
 
    location ~ .*\.(js|css)?$
    {
        expires 1h;
    }


配置虚拟主机:

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

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

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

 


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;
}



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务