nginx

一,nginx的location设置

设置图片过期,既是设置http头的Expires和Cache-Control头,过期时间为一个月

 location ~* \.(gif|jpg|jpeg|png|ico|rar)$ {
        expires 1M;
    }

 

二,修改首页文件及重定向

如果输入地址栏的是目录路径,首先寻找xxx/xxx.html,未找到后再找index.html

index xxx/xxx.html index.html;

 

访问abc.com将301到def.com

server {
    server_name  abc.com;
    rewrite ^(.*) http://def.com$1 permanent;
}

 

三,nginx安装

1,

sudo ./configure --user=nginx --group=nginx --pid-path=/opt/nginx/nginx.pid --prefix=/opt/nginx --with-pcre --with-debug

 

出错:

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

解决:

sudo apt-get install libpcre3 libpcre3-dev

 

出错:/configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.

 

解决:

sudo apt-get install libssl-dev

 

2, sudo make  && sudo make install

 

3,启动

添加用户及用户组

sudo groupadd nginx

sudo useradd -g nginx nginx

 

sudo /opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf

你可能感兴趣的:(html,nginx,cache)