Nginx高级使用
1.用户认证
客户端访问限制
deny 客户端地址; 拒绝访问
allow 客户端地址; 允许访问
rpm -q httpd-tools yum -y install httpd-tools
user
htpasswd -h [root@lk_Cloud ~]# htpasswd -c /usr/local/nginx/conf/user.txt admin New password: Re-type new password: Adding password for user admin
cat /usr/local/nginx/conf/user.txt admin:ytAJoGw8jjbJI
vim nginx.conf
location / { root /admindir; index index.html; #allow 1.1.1.1; #deny all; auth_basic "please in put user and password"; auth_basic_user_file "/usr/local/nginx/conf/user.txt"; }
2.源码包平滑升级
查看现在版本
/usr/local/nginx/sbin/nginx -V
下载最新源码包
编译选项务必保持一致
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module make
先备份老版本启动文件
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginxold make之后产生的objs目录 cp objs/nginx /usr/local/nginx/sbin/ 在新版本解压目录下执行 make upgrade
3.防盗链
server { ....... location ~* \.(png|jpeg|jpg|gif)$ { valid_referers none blocked www.kamilliu.com .kamilliu.com ; if ($invalid_referer){ #rewrite ^/ http://1.1.1.254/err.html; return 404; } } ..... }
公众号请关注:侠之大者