nginx打开了auth_basic模式,让输入账号密码才能访问网站,以便保护隐私。
可是在微信里面,没有弹出验证的弹窗。
直接显示的没有输入账号密码的样子。
还根本就没法解决,至少眼前我不知道怎么解决。于是我用了代理的方式,判定一下,如果是微信打开就不验证,但是取消autoindex;其他页面还是需要验证,并且有autoindex
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
server { listen 80; charset utf-8; server_name sample_normal; root /data/web/bpo_git/www/sample; index index.html index.htm index.php; location /{ autoindex on; auth_basic "passwd same to mail"; auth_basic_user_file /data/git/cert/passwd; } location ~ \.php$ { include php/enable_php5.conf; } } server { listen 80; charset utf-8; server_name sample_wx; root /data/web/bpo_git/www/sample; index index.html index.htm index.php; location ~ \.php$ { include php/enable_php5.conf; } } server { listen 80; charset utf-8; server_name sample.vogso.com; root /data/web/bpo_git/www/sample; index index.html index.htm index.php; location /{ if ( $http_user_agent ~* "MicroMessenger" ){ proxy_pass http://sample_wx; } if ( $http_user_agent !~* "MicroMessenger" ){ proxy_pass http://sample_normal; } } location ~ \.php$ { include php/enable_php5.conf; } access_log /data/log/nginx/access/sample.log main; } |
因为不是每个属性都可以在if里面使用,我开始想在if里面使用auth,可是这个属性不让在location的if中使用。于是我只能又多写了两个server,然后建立了两个本地才能访问的host,一个是普通页面“sample_normal”,一个是微信的“sample_wx”。最后,再建立了一个正常域名的server,判断“http_user_agent”是否包含“MicroMessenger”,判断是否是微信(nginx中有if但是没有else),然后代理到相应的域名去。