一,傻瓜式安装
- 在widdows中nginx.exe运行文件是不能进行双击点击的,需要在该目录下使用cmd进入
- 在nginx中的命令有
- 启动:
C:servernginx-1.0.2>start nginx(建议使用,因为不会出现一直在开启的状态,同时可以再次的输入命令)- 或
C:servernginx-1.0.2>nginx.exe- 停止:
C:servernginx-1.0.2>nginx.exe -s stop或
C:servernginx-1.0.2>nginx.exe -s quit
注:stop是快速停止nginx,可能并不保存相关信息;quit是完整有序的停止nginx,并保存相关信息。- 重新载入Nginx:
C:servernginx-1.0.2>nginx.exe -s reload
当配置信息修改,需要重新载入这些配置时使用此命令。- 重新打开日志文件:
C:servernginx-1.0.2>nginx.exe -s reopen- 查看Nginx版本:
C:servernginx-1.0.2>nginx -v3,在浏览器url栏中进行测试
localhost:80 或者是localhost,若出现有
Welcome to nginx!If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.Thank you for using nginx.
说明安装成功
二,使用说明,主要的使用是方向代理
如果proxy_pass后面没有任何URL路径信息(比如/,/xxx等),则反向代理的地址会包含location中的匹配部分,否则只会拼接匹配后的剩余路径
- 解释:没有url路径信息:就是在url后面拼接location中的全部路径
- 解释:含有url路径信息:就是在url后面拼接location中剩余路径
假设请求:http://localhost/online/wxapi/test/loginSwitch
- 第一种情况
proxy_pass结尾有/
location /online/wxapi/ { proxy_pass http://localhost:8080/; proxy_set_header X-Real-IP $remote_addr; }代理后的实际地址:http://localhost:8080/test/loginSwitch
第二种情况proxy_pass最后没有/
location /online/wxapi/ { proxy_pass http://localhost:8080; proxy_set_header X-Real-IP $remote_addr; }代理后的实际地址:http://localhost:8080/online/wxapi/test/loginSwitch
- 第三种情况
proxy_pass最后有/web
location /online/wxapi/ { proxy_pass http://localhost:8080/web; proxy_set_header X-Real-IP $remote_addr; }代理后的实际地址:http://localhost:8080/webtest/loginSwitch
注意:因为是拼接剩余部分,所以路径中可能有单个词的拼接,比如webtest
注意:在正常的项目开发的过程中是使用第二种方法
三,使用所需要配合的工具
- host文件的修改,路径为:C:WindowsSystem32driversetc下,通常是使用复制到界面上,进行添加:127.0.0.1 www.sphskla.cn
- 解释:就是将www.sphskla.cn 的请求都变成本地127.0.0.1,两者是等价关系
- 在ngnix中
location ~ /wx { proxy_pass http://localhost:8099; }就能把方法的本地localhost地址转换到本地的8099端口中- 在使用nginx必须要启动才能开始使用。
二,微信扫码登录(依据微信开放平台,由于微信官方申明,个人的很多消息都不能看了)
微信登录,获取微信二维码和access_token
3,获取用户的基本信息
public String getOauthAccessToken(String code,String wxMpAppId,String wxMpAppSecret) { return "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + wxMpAppId + "&secret=" + wxMpAppSecret+ "&code=" + code + "&grant_type=" + WxConstant.GRANT_TYPE; } public String getUserInfo(String accessToken, String openId) { return "https://api.weixin.qq.com/sns/userinfo?access_token=" + accessToken.trim() + "&openid=" + openId.trim()+ "&lang=zh_CN"; } public String getWxWebLoginUrl(String type,String redirectUrl,String param,String wxOpenAppId){ return "https://open.weixin.qq.com/connect/qrconnect?appid="+wxOpenAppId+"&redirect_uri="+redirectUrl+"&response_type=code&scope="+type+"&state="+param+"#wechat_redirect"; }
三,数据的转换(使用ali的依赖)
- 将java类转为json
JSON.toJSONString(new Result().setCode(200).setMessage("微信登录失败").setData(map));
2,将json转化成java类
(1)JSONObject jsonObject = JSONObject.parseObject(json字符串);accessToken = JSONObject.toJavaObject(jsonObject, AccessToken.class);(2)
WechatUser people = JSON.parseObject(content1,WechatUser.class);



