博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【原创】学习日记2:nginx配置文件2012.01.06
阅读量:4481 次
发布时间:2019-06-08

本文共 2010 字,大约阅读时间需要 6 分钟。

本文承接 一文

【首先】

nginx.conf  最上面的的usr 改为root
【其次】
看下面最后一行 include 包含的*.conf
新建个文件如 test.conf
内容如下:

server {    listen       80;    server_name  www.test.com;    #charset koi8-r;    access_log  /var/log/nginx/test.access.log  main;    error_log  /var/log/nginx/test.error.log;    location / {        root   /var/www/html/test/;        index  index.php;    }    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   /usr/share/nginx/html;    }    # 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           /var/www/html/test/;        fastcgi_pass   127.0.0.1:9000;        fastcgi_index  index.php;        fastcgi_param  SCRIPT_FILENAME  /var/www/html/test$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;    #}}

【设置浏览器缓存时间(expires)】

   在配置文件server块中,增加以下内容。

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

   以上设置中,第一个表示所有gif、jpg、jpeg、png、bmp、wsf文件,在访问后的30天后缓存失效;第二个表示所有js、css文件,在访问后的1小时后缓存失效。

【设置反向代理】
   例如,将域名下所有php请求转交给apache处理,我们可以在配置文件相应server块中,设置如下内容。

location ~ \.php$ {      proxy_pass   http://127.0.0.1:8080;      proxy_set_header Host $host;      proxy_set_header X-Forwarded-For $remote_addr;   }

【压缩设置】

   在配置文件http块中找到"# gzip on;",将gzip前的#号去掉,并在下一行增加以下内容。

gzip_min_length 1k;   gzip_buffers 4 16k;   gzip_http_version 1.1;   gzip_comp_level 2;   gzip_types text/plain application/x-javascript text/css application/xml;   gzip_vary on;

gzip_types表示启用压缩文能的文件头,以上设置为文本、js、css、xml进行文件压缩。

转载于:https://www.cnblogs.com/wangjiafang/archive/2013/01/07/2848862.html

你可能感兴趣的文章
Hadoop集群时钟同步
查看>>
C++二维数组讲解、二维数组的声明和初始化
查看>>
纹理映射和混合
查看>>
PHP获取域名、IP地址的方法
查看>>
php验证复选框的小例子
查看>>
Sql Server 判断表或数据库是否存在
查看>>
计算机网络
查看>>
iOS-浅谈runtime运行时机制
查看>>
数字证书原理 - 转自 http://www.cnblogs.com/JeffreySun/archive/2010/06/24/1627247.html
查看>>
关于float和margin
查看>>
【原创】StreamInsight查询系列(七)——基本查询操作之基础排序
查看>>
C# 安装包制作
查看>>
【P2564】生日礼物(单调队列)
查看>>
Instuments工具
查看>>
新创建django项目,但网页打不开127.0.0.1:8000
查看>>
Python练习-内置函数的应用
查看>>
洛谷P3905 道路重建
查看>>
数据表格 - DataGrid - 行编辑
查看>>
HQL查询语句
查看>>
jsp听课笔记(四)
查看>>