nginx常用配置
![img_30a613694a370f5713f0be55ca601381.png](https://i-blog.csdnimg.cn/blog_migrate/dec0cf5889011efc0180e11fba4cf4fd.png)
![img_98e69d4eab27913fed307db7dd645647.png](https://i-blog.csdnimg.cn/blog_migrate/f3261169789187861c6e57bd2e6efd21.png)
![img_88a698a24f3b49f7bcf6df8d3efc2de4.png](https://i-blog.csdnimg.cn/blog_migrate/4d61f303b21d67cac87af9ca57364fdc.png)
include vhost/*.conf
用户认证
location / {
auth_basic "Auth"
auth_basic_user_file /usr/local/nginx/conf/htpasswd
}
server {
listen 80;
server_name test.com test.com2;
index index.html index.jsp;
root /data/ddd
if (http://www.123.com/$1 permanent;
}
}
permanent = [R=301]
redirect = [R=302]
access_log /tmp/aa.log combinated_realip;
kill -HUP cat $nginx_pid
location ~ .*.(gif|jpg|jpeg|png|bmp|swf){
expires 12h;
access_log off;
}
nginx 图片防盗链
location ~* ^.+.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)invalid_referer){
return 403;
}
access_log off;
}
location /data/{
allow 192.168.1.1;
allow 172.12.0.0;
deny all;
}
if ($http_user_agent ~ 'Spider/Tomato'){
return 403;
}
![img_e1e39e4d1febf897f56c15681106deff.png](https://i-blog.csdnimg.cn/blog_migrate/08867c0f4763d41386b9ea94ba3e6314.png)
proxy_pass http://xx;
proxy_set_header Host remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forward_for;
upstream aa{
ip_hash;
server 33:33;
server xx:ss;
}
server {
ssl on;
ssl_certificate xx.crt;
ssl_certificate_key xx.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
}