nginx-优化集合

一直以来,我的个人博客都是挂在美帝的vps上(没办法,谁让我没本事,出不了国呢,只能挂个vps上偶尔也享受下墙外世界的美好)
博客主要记录下自己的岁岁年年,留给未来的下一代,翻看感受下他老爸那个年代是怎么苦逼度过的~~

也许哪一天我的 儿子女儿/孙子孙女/重孙/重孙女 ,他们无意间用古老的搜索引擎 看到了他父辈的电子日记!他们一定会说:“好老土!,爸爸/爷爷  原来年轻的时候长这样 🙂 ”

也许我不能活100年 ,但我希望在我离世的时候 ,交齐后面500年的域名费+空间费! 哈哈,并签订一个合同!如果我的网页那天访问不了,可以以此申请巨额赔偿。。。。

 有点意思,这个桥段 让我想起了 《布达佩斯大饭店》里面那个贵妇的遗嘱。。。。 🙂   推荐大家一定要看看,一部很有深度的片子!大概就是一家豪华的大饭店,见证了半个世纪的欧洲发展!

  套用网上的一句影评:

人生近看是悲剧,远看是喜剧。–by 卓别林

 

回归正题,写这篇日记的初衷主要是想努力提高博客的加载速度,要知道 墙内打开墙外的网站是非常苦逼的。。。于是乎各种关于nginx 的优化技巧收集而成拼凑了此文。。。。 可以速度提升非常的明显!! 🙂

#首先是环境 rhel/centos/ubuntu/debian

apt-get install openssl libssl-dev  build-essential  curl libreadline-dev libncurses5-dev libpcre3-dev libssl-dev perl make build-essential zlib1g-dev libpcre3 libpcre3-dev geoip-database libgeoip-dev libgd2-xpm libgd2-xpm-dev libgd2-xpm libgd2-xpm-dev  libxml2 libxml2-dev libxslt-dev -y
yum install readline-devel pcre-devel openssl-devel gcc-c++ pcre-dev pcre-devel zlib-devel make geoip-devel GeoIP GeoIP-data libxml2-devel libxslt-devel GeoIP-devel   gd-devel -y

#tips 有时需要 tcp 负载均衡
#打上 tcp 负载均衡补丁  默认没有提供TCP协议的负载均衡

tar -xvzf nginx-1.6.3.tar.gz
cd nginx-1.6.3
patch -p1 < ../nginx_tcp_proxy_module-master/tcp.patch

#出现几个 succeeded 就ok 了

#更改 nginx 的 nginx 版本和显示

vim /opt/nginx-dir/nginx-1.6.3/src/http/ngx_http_header_filter_module.c +50
#修改 49,50 行左右
static char ngx_http_server_string[] = "Server: eIDServer" CRLF;
static char ngx_http_server_full_string[] = "Server: eIDServer" CRLF;

#安装google tcmalloc 模块的依赖  可选项/一般我用 jemalloc 替换

tar xvzf libunwind-1.1.tar.gz
cd libunwind-1.1
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install

#安装google tcmalloc模块

tar xvzf gperftools-2.2.1.tar.gz
cd gperftools-2.2.1
./configure
make
make install
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig

#jemalloc 内存优化模块

wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2
tar xjf jemalloc-3.6.0.tar.bz2
cd jemalloc-3.6.0
./configure
make && make install
echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
ldconfig

#安装缓存优化模块

tar xvzf ngx_openresty-1.7.7.2.tar.gz
cd ngx_openresty-1.7.7.2/
./configure
make
make install

#安装google ngx_pagespeed 加速模块

unzip ngx_pagespeed-master.zip
cd ngx_pagespeed-master
tar xvzf 1.9.32.4.tar.gz

#安装 开源web 防火墙模块 (需要yum install libxml2-devel httpd-devel) 可选项

tar -zxvf modsecurity-2.9.0.tar.gz
cd modsecurity-2.9.0
./configure --enable-standalone-module --disable-mlogc
make

#ubuntu 安装 modsecurity-2.9
# ubuntu需要安装 apt-get install build-essential libpcre3 libpcre3-dev libssl-dev libtool autoconf apache2-prefork-dev libxml2-dev libcurl4-openssl-dev apache2-prefork-dev
# cd /usr/src/ModSecurity-2.9.0/
# ./autogen.sh
# ./configure --enable-standalone-module   --disable-apache2-module  
# make

#官方实例 安装 google 加速模块[需要翻墙的]  如果上面已经安装了 就可以不要安装此步,这里只是作为参考

#To install our dependencies, run:

#RedHat, CentOS, or Fedora

sudo yum install gcc-c++ pcre-devel zlib-devel make unzip

#Ubuntu or Debian
sudo apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev unzip

#Then download ngx_pagespeed:
cd
NPS_VERSION=1.9.32.4
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-${NPS_VERSION}-beta.zip
unzip release-${NPS_VERSION}-beta.zip
cd ngx_pagespeed-release-${NPS_VERSION}-beta/
wget https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}.tar.gz
tar -xzvf ${NPS_VERSION}.tar.gz  # extracts to psol/

#Download and build nginx with support for pagespeed:

cd
# check http://nginx.org/en/download.html for the latest version
NGINX_VERSION=1.8.0
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
tar -xvzf nginx-${NGINX_VERSION}.tar.gz
cd nginx-${NGINX_VERSION}/
./configure --add-module=$HOME/ngx_pagespeed-release-${NPS_VERSION}-beta
make
sudo make install

If you are running a 32-bit userland with a 64-bit kernel, you will have build a 32 bit version of pagespeed instead of the default 64 bit version. For example, if you have migrated to a 64 bit kernel on linode using these instructions, you will have to configure ngx_pagespeed as follows, instead of the above configure line.
setarch i686 ./configure –add-module=$HOME/ngx_pagespeed-release-${NPS_VERSION}-beta
If this doesn’t work for you, please let us know. You can post on our discussion group or file a bug.
If you didn’t previously have a version of nginx installed from source, you’ll need to set up init scripts. See wiki.nginx.org/InitScripts.

#编译nginx  注意替换路径

./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --http-client-body-temp-path=/usr/local/nginx/temp/body  --http-fastcgi-temp-path=/usr/local/nginx/temp/fastcgi --http-proxy-temp-path=/usr/local/nginx/temp/proxy --http-scgi-temp-path=/usr/local/nginx/temp/scgi --http-uwsgi-temp-path=/usr/local/nginx/temp/uwsgi  --pid-path=/usr/local/nginx/logs/nginx.pid --with-http_stub_status_module --with-http_ssl_module --with-pcre=/opt/nginx-dir/pcre-8.36 --add-module=/opt/nginx-dir/nginx-upstream-fair-master --with-http_realip_module --with-poll_module --add-module=/opt/nginx-dir/nginx_tcp_proxy_module-master --add-module=/opt/nginx-dir/ngx_pagespeed-master  --with-openssl=/opt/nginx-dir/openssl-1.0.2c --with-zlib=/opt/nginx-dir/zlib-1.2.8  --with-cc-opt='-O3' --with-google_perftools_module --add-module=/opt/nginx-dir/echo-nginx-module-0.56  --with-http_geoip_module --with-http_addition_module --with-http_dav_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_xslt_module --with-ipv6 --with-mail --with-mail_ssl_module --with-http_spdy_module  --with-http_mp4_module --with-http_flv_module --add-module=/opt/nginx-dir/modsecurity-2.9.0

#jemalloc 模式 注意替换路径

./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --http-client-body-temp-path=/usr/local/nginx/temp/body  --http-fastcgi-temp-path=/usr/local/nginx/temp/fastcgi --http-proxy-temp-path=/usr/local/nginx/temp/proxy --http-scgi-temp-path=/usr/local/nginx/temp/scgi --http-uwsgi-temp-path=/usr/local/nginx/temp/uwsgi  --pid-path=/usr/local/nginx/logs/nginx.pid --with-http_stub_status_module --with-http_ssl_module --with-pcre=/opt/nginx-dir/pcre-8.36 --add-module=/opt/nginx-dir/nginx-upstream-fair-master --with-http_realip_module --with-poll_module --add-module=/opt/nginx-dir/nginx_tcp_proxy_module-master --add-module=/opt/nginx-dir/ngx_pagespeed-master  --with-openssl=/opt/nginx-dir/openssl-1.0.2c --with-zlib=/opt/nginx-dir/zlib-1.2.8  --with-cc-opt='-O3'  --add-module=/opt/nginx-dir/echo-nginx-module-0.56  --with-http_geoip_module --with-http_addition_module --with-http_dav_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_xslt_module --with-ipv6 --with-mail --with-mail_ssl_module --with-http_spdy_module  --with-http_mp4_module --with-http_flv_module --add-module=/opt/nginx-dir/modsecurity-2.9.0  --with-ld-opt="-ljemalloc"

make
make install
make upgrade
mkdir /usr/local/nginx/temp

# 开启nginx的pagespeed模块
在nginx的 server区域 配置文件中加入如下 ,我建议单独做个 conf

pagespeed on;
pagespeed FileCachePath /tmp/ngx_pagespeed_cache;
pagespeed RewriteLevel CoreFilters;
pagespeed UseExperimentalJsMinifier on;

pagespeed EnableFilters add_head;
pagespeed EnableFilters extend_cache;
pagespeed EnableFilters fallback_rewrite_css_urls;
pagespeed EnableFilters flatten_css_imports;
pagespeed EnableFilters inline_css;
pagespeed EnableFilters inline_import_to_link;
pagespeed EnableFilters inline_javascript;
pagespeed EnableFilters local_storage_cache;
pagespeed EnableFilters collapse_whitespace,remove_comments;
pagespeed EnableFilters outline_css;
pagespeed EnableFilters flatten_css_imports;
pagespeed EnableFilters move_css_above_scripts;
pagespeed EnableFilters move_css_to_head;
pagespeed EnableFilters outline_javascript;
pagespeed EnableFilters combine_javascript;
pagespeed EnableFilters combine_css;
pagespeed EnableFilters rewrite_javascript;
pagespeed EnableFilters rewrite_css,sprite_images;
pagespeed EnableFilters rewrite_style_attributes;
pagespeed EnableFilters rewrite_images;
pagespeed EnableFilters recompress_images;
pagespeed EnableFilters resize_images;
pagespeed EnableFilters convert_meta_tags;
pagespeed EnableFilters lazyload_images;
pagespeed EnableFilters insert_dns_prefetch;

location ~ ".pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+" { add_header "" ""; }
location ~ "^/ngx_pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all; }
location /ngx_pagespeed_message { allow 127.0.0.1; deny all; }

#创建临时目录

mkdir /tmp/ngx_pagespeed_cache
chown -R www:www /tmp/ngx_pagespeed_cache
chmod -R 777 /tmp/ngx_pagespeed_cache

#去除隐藏 pagespeed  版本号
pagespeed XHeaderValue "Powered By eblis";

#去除隐藏  X-Powered-By 版本号
# like /etc/php.ini, /etc/php5/apache2/php.ini, etc.  /usr/local/php/etc/php.ini ) locate the line containing “expose_php On”_ and set it to Off:
#(如果启用了 php  请在 设置 expose_php = Off;)

#官方google pagespeed 样列

Nginx:

    http {
      pagespeed On;
      pagespeed FileCachePath "/var/cache/ngx_pagespeed/";
      pagespeed EnableFilters combine_css,combine_javascript;

      server {
        listen 80;
        server_name www.example1.com;
        root /www/example1;
        pagespeed MapRewriteDomain cdn.example1.com *example.com;
      }

      server {
        listen 80;
        server_name www.example2.org;
        root /www/example2;
        pagespeed MapRewriteDomain cdn.example2.org *example.org;
        # Don't want combine_css here
        pagespeed DisableFilters combine_css;
      }

      server {
        listen 80;
        server_name www.example3.org;
        root /www/example3;

        # mod_pagespeed off for this virtual host
        pagespeed off;
      }

#让后台的nginx 获取 ip 的区域,显示更加直观

#下载免费的geo_city数据库
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
#下载免费的geo_coundty数据库
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
#在debian中安装libgeoip:
sudo apt-get install libgeoip-dev
#其它系统,你可以下载并编译一个源文件
wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz
在centos可以用yum安装:
yum install geoip

tar xvzf GeoIP.tar.gz
cd GeoIP-1.4.8/
./configure
make && make install
echo '/usr/local/lib' > /etc/ld.so.conf.d/geoip.conf
ldconfig

gunzip GeoIP.dat.gz
配置 Nginx

最后是配置 nginx,在相关地方加上如下的配置就可以了:

$geoip_city_country_code; -国家名的前两个字母, 如, “RU”, “US”.
$geoip_city_country_code3; – 国家名的前三个字母, 如, “RUS”, “USA”.
$geoip_city_country_name; -国家名称, 如, “Russian Federation”, “United States”.
$geoip_region; – 省,州或区名 (province, region, state, province, federal land, and the like), 如, “Moscow City”, “DC”.
$geoip_city; – 城市名称, 如, “Moscow”, “Washington”.
$geoip_postal_code; – 邮政编号.
$geoip_latitude: 纬度
$geoip_longitude: 经度

#如下

http{

   
     ....
     server {
                listen  80 default;
                server_name  _;

               
                root /var/www/html;
                location / {
                        index index.html;
                }
        }
}

# vi /etc/nginx/nginx.conf

http {
...
geoip_country /usr/local/nginx/geoip/GeoIP.dat;
geoip_city    /usr/local/nginx/geoip/GeoLiteCity.dat;

#GeoIP
fastcgi_param GEOIP_COUNTRY_CODE $geoip_city_country_code;
fastcgi_param GEOIP_COUNTRY_CODE3 $geoip_country_code3;
fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name;
fastcgi_param GEOIP_CITY_COUNTRY_CODE $geoip_city_country_code;
fastcgi_param GEOIP_CITY_COUNTRY_CODE3 $geoip_city_country_code3;
fastcgi_param GEOIP_CITY_COUNTRY_NAME $geoip_city_country_name;
fastcgi_param GEOIP_REGION $geoip_region;
fastcgi_param GEOIP_CITY $geoip_city;
fastcgi_param GEOIP_POSTAL_CODE $geoip_postal_code;
fastcgi_param GEOIP_CITY_CONTINENT_CODE $geoip_city_continent_code;
fastcgi_param GEOIP_LAT $geoip_latitude;
fastcgi_param GEOIP_LNG $geoip_longitude;

 ## Log Format设置日志格式,结尾添加了三个字段
 log_format  access  '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" '   '"$http_user_agent" "$http_x_forwarded_for" ' '$geoip_country_name $geoip_region $geoip_city $geoip_postal_code $geoip_city_country_code';

}

server {
...

         access_log /home/logs/localhost_access.log access;
        location / {
            root   /home//www;
            if ($geoip_country_code = CN) {
                root /home/cn;
            }
            ...
        }
...
}

#在nginx.conf 添加 tcmalloc 模块

#在以下模块之间添加如下即可
events{
    worker_connections 1024;
    }

    google_perftools_profiles /tmp/tcmalloc;

http{
    ...........
    }
    

#使用验证lsof命令查看tcmalloc是否起效:
如lsof没有装,可yum/apt安装
lsof -n | grep tcmalloc

3)完成之后,需要将/usr/local/nginx/logs 目录设置为可写权限,里面是一系列得日志文件:
chmod 777 -R /usr/local/nginx/logs
nginx #启动 nginx
curl -i http://localhost

4)配置 Nginx 为系统服务
1、 配置到系统 path 中
# sudo vim /etc/bash.bashrc
在该文件最后添加:

if [ -d “/usr/local/nginx/sbin” ]; then
PATH=”$PATH:/usr/local/nginx/sbin”

fi

2、添加启动管理文件并让 ubuntu 开机时自动运行 nginx 网页服务器
# wget http://nginx-init-ubuntu.googlecode.com/files/nginx-init-ubuntu_v2.0.0-RC2.tar.bz2
# tar jxvf nginx-init-ubuntu_v2.0.0-RC2.tar.bz2
# sudo vim nginx
更改 nginx 安装路径及 nginx 配置文件路径

PATH=/usr/local/nginx/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/nginx/sbin/nginx
PS="nginx"                
PIDNAME="nginx"            
PIDFILE=$PIDNAME.pid          
PIDSPATH=/var/run            
DESCRIPTION="Nginx Server..."    
RUNAS=root               
SCRIPT_OK=0              
SCRIPT_ERROR=1            
TRUE=1
FALSE=0
lockfile=/var/lock/subsys/nginx
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

将该文件放到/usr/local/nginx 下并设为可执行,并且添加软连到/etc/init.d 执行:

# sudo mv nginx /usr/local/nginx
# chmod +x /usr/local/nginx/nginx
# sudo ln -s /usr/local/nginx/nginx /etc/init.d/nginx   #添加软连到/etc/init.d 目录下
# update-rc.d -f nginx defaults
启动和停止/重启命令:

#sudo /etc/init.d/nginx start
#sudo /etc/init.d/nginx stop
#sudo /etc/init.d/nginx restart

完成。

#查看当前的 连接数

netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

#最后送给懒人们,已经配置优化好的 /usr/local/nginx/conf/nginx.conf ( 基本都有了可以在加一些安全方面的设置)

user  www-data;
worker_processes auto;
worker_rlimit_nofile 519600;
error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;

events {
    use epoll;
    worker_connections 409600;
    epoll_events 51200;
}

#for tcmalloc   #如果使用了 jemalloc 请注释这行
#google_perftools_profiles /tmp/tcmalloc;

http {

    include       pagespeed.conf;
    include       mime.types;
    default_type  application/octet-stream; 

    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 50m; 

    sendfile on;
    tcp_nopush     on; 

    keepalive_timeout 70; 

    tcp_nodelay on; 

    limit_req_log_level warn;
    limit_req_zone $binary_remote_addr zone=ONLY_ten:10m rate=10000r/s;        

    fastcgi_intercept_errors on;

    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 256k; 

    gzip on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 9;
    #gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_types     text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php   application/xml+rss application/javascript;
    #这里最好不要添加图片的压缩,否则只会越来越大

    gzip_vary on;
    gzip_proxied        expired no-cache no-store private auth;
    gzip_disable        "MSIE [1-6].";

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';

    geoip_country /usr/local/nginx/geoip/GeoIP.dat;
    geoip_city    /usr/local/nginx/geoip/GeoLiteCity.dat;

    include geoip.conf;

    log_format  get_location  '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" '   '"$http_user_agent" "$http_x_forwarded_for" ' '$geoip_country_name $geoip_region $geoip_city $geoip_postal_code $geoip_city_country_code';

    server_tokens off;
    include vhost/*.conf;
}

#以下是 /usr/local/nginx/conf/pagespeed.conf 的常规配置

pagespeed on;
pagespeed FileCachePath /tmp/ngx_pagespeed_cache;
pagespeed RewriteLevel CoreFilters;
pagespeed UseExperimentalJsMinifier on;

pagespeed EnableFilters add_head;
pagespeed EnableFilters extend_cache;
pagespeed EnableFilters fallback_rewrite_css_urls;
pagespeed EnableFilters flatten_css_imports;
pagespeed EnableFilters inline_css;
pagespeed EnableFilters inline_import_to_link;
pagespeed EnableFilters inline_javascript;
pagespeed EnableFilters local_storage_cache;
pagespeed EnableFilters collapse_whitespace,remove_comments;
pagespeed EnableFilters outline_css;
pagespeed EnableFilters flatten_css_imports;
pagespeed EnableFilters move_css_above_scripts;
pagespeed EnableFilters move_css_to_head;
pagespeed EnableFilters outline_javascript;
pagespeed EnableFilters combine_javascript;
pagespeed EnableFilters combine_css;
pagespeed EnableFilters rewrite_javascript;
pagespeed EnableFilters rewrite_css,sprite_images;
pagespeed EnableFilters rewrite_style_attributes;
pagespeed EnableFilters rewrite_images;
pagespeed EnableFilters recompress_images;
pagespeed EnableFilters resize_images;
pagespeed EnableFilters convert_meta_tags;
pagespeed EnableFilters lazyload_images;
pagespeed EnableFilters insert_dns_prefetch;
pagespeed XHeaderValue "tiaoh.com :)";
#以下是 /usr/local/nginx/conf/geoip.conf 的常规配置
#geoip
fastcgi_param GEOIP_COUNTRY_CODE  $geoip_city_country_code;
fastcgi_param GEOIP_COUNTRY_CODE3 $geoip_country_code3;
fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name;
fastcgi_param GEOIP_CITY_COUNTRY_CODE $geoip_city_country_code;
fastcgi_param GEOIP_CITY_COUNTRY_CODE3 $geoip_city_country_code3;
fastcgi_param GEOIP_CITY_COUNTRY_NAME $geoip_city_country_name;
fastcgi_param GEOIP_REGION $geoip_region;
fastcgi_param GEOIP_CITY $geoip_city;
fastcgi_param GEOIP_POSTAL_CODE $geoip_postal_code;
fastcgi_param GEOIP_CITY_CONTINENT_CODE $geoip_city_continent_code;
fastcgi_param GEOIP_LAT $geoip_latitude;
fastcgi_param GEOIP_LNG $geoip_longitude;
#以下是 /usr/local/nginx/conf/vhost/default_server.conf 的常规配置
 

server
{
    listen 80 default_server;
    #listen [::]:80 default_server ipv6only=on;
    server_name _;

    index index.html index.htm index.php;
    root  /home/wwwroot/default;
 return       404;

    #error_page   404   /404.html;
    include enable-php.conf;

    location /nginx_status
    {
        stub_status on;
        access_log   off;
    }

    location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
    }

    location ~ .*.(js|css)?$
    {
        expires      12h;
    }

    location ~ /.
    {
        deny all;
    }

    access_log  /home/wwwlogs/access.log  access;
}
#以下是 /usr/local/nginx/conf/vhost/default_vhost-http-80.conf 的常规配置
 

server
{
    server_name blog.tiaoh.com;
    # autoindex on;
    listen 80;
    access_log logs/get_location_access.log get_location;
    #   access_log logs/access_log.log main;
    limit_req zone=ONLY_ten burst=10000;

    error_page 404 /404.html;
    location  /404.html {}

    include pagespeed.conf;
    
    location ~ ".pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+" { add_header "" "";  }
    location ~ "^/ngx_pagespeed_static/" {  }
    location ~ "^/ngx_pagespeed_beacon$" {  }
    location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all;  }
    location /ngx_pagespeed_message { allow 127.0.0.1; deny all;  }

}

 

发表评论

This site uses Akismet to reduce spam. Learn how your comment data is processed.