栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Windows下使用nginx

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Windows下使用nginx

一,傻瓜式安装

  1. 在widdows中nginx.exe运行文件是不能进行双击点击的,需要在该目录下使用cmd进入
  2. 在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 -v

3,在浏览器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的依赖)

  1.  将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);

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/830344.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号