openresty安装lua和nginx相关
server{ listen 80; server_name a.com; index index.php; root /usr/share/nginx/html; location / { if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last; break; } } location ~ \.php { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include ./conf.d/fcgi.conf; set $real_script_name $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") { set $real_script_name $1; set $path_info $2; } fastcgi_param SCRIPT_FILENAME $document_root$real_script_name; fastcgi_param SCRIPT_NAME $real_script_name; fastcgi_param PATH_INFO $path_info; }
location ~* .(jpg|gif|png|js|css)$ { if (-f $request_filename) { expires 30d; break; }
}
nginx 忽略大小写安装nginx lua模块
手动编译nginx,安装lua-nginx-module步骤
1,环境支持
apt-get install libreadline-dev libncurses5-dev libpcre3-dev \ libssl-dev perl make build-essential apt-get install postgresql-9.3 postgresql-server-dev-9.3
2,下载openresty
sudo wget https://openresty.org/download/openresty-1.11.2.2.tar.gz
3,编译
sudo ./configure --prefix=/usr/local/openresty \ --with-luajit \ --without-http_redis2_module \ --with-http_iconv_module \ --with-http_postgres_module
4,配置nginx访问路径
sudo ln -s /usr/local/openresty/nginx/sbin/nginx /usr/local/sbin/nginx
5,启动 sudo nginx
结束.
Nginx简单防盗链
静态文件匹配处改为如下 location ~ .*\.(jpg|jpeg|JPG|png|gif|icon)$ { valid_referers blocked www.qixing318.com qixing318.com; if ($invalid_referer) { return 404; } }
Nginx禁止访问目录
location ~* \.(txt|doc)${ root /data/www/wwwroot/linuxtone/test; deny all; }
Nginx设置缓存
proxy_cache_path /path/to/cache levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m use_temp_path=off; server { ... location / { proxy_cache my_cache; proxy_cache_revalidate on; proxy_cache_min_uses 3; proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504; proxy_cache_lock on; proxy_pass http://my_upstream; } }
详细文档讲解
https://moonbingbing.gitbooks.io/openresty-best-practices/content/ngx/static_file.html
参考文档:
http://openresty.org/cn/installation.html
https://moonbingbing.gitbooks.io/openresty-best-practices/content/ngx/nginx_local_pcre.html