小程序配置nginx 通过https访问若依后台端口接口

重点:域名必须备案;
nginx 相关配置


server {
    listen 443 ssl;
    server_name 域名;

	ssl_certificate     E://nginx-1.15.6/conf/pfx/xxx.crt;
    ssl_certificate_key	E://nginx-1.15.6/conf/pfx/xxx.key;
	ssl_session_cache   shared:SSL:1m;  
	ssl_session_timeout 5m;  
	ssl_ciphers         HIGH:!aNULL:!MD5;         
	ssl_prefer_server_ciphers  on; 

	#这里配置相当于直接把https(443)端口代理成了8100
    location / {
        proxy_pass http://localhost:8100;
        fastcgi_param   HTTPS               on;
		fastcgi_param   HTTP_SCHEME         https;
    }
}
# 若依后台相关配置  也可以参考上面多端口配置
server {
	listen       8101;
	server_name  localhost;
	# 将dist文件放到Nginx 的hml文件下(推荐)
	location / {
		root	html/dapengdist;
		index	index.html;
		try_files $uri $uri/ /index.html;
	}
	location /prod-api/ {
		proxy_set_header Host $http_host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header REMOTE-HOST $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_pass http://localhost:8100/;
	}
	# 下面的配置解决在某个界面重复刷新500的bug
	error_page	500 502 503 504 404 400  /dapengdist/index.html;
	location = /dapengdist/index.html {
		root   html;
	}
}

正向代理 重写请求路径(rewrite)

主要配置逻辑

#如果你想将URL中的"abc"替换为"xyz",你可以使用以下代码:
location / {
    rewrite ^(.*)abc(.*)$ $1xyz$2 break;
    rewrite ^(.*)$ $1;
}

配置案例 443端口配置俩请求 location 第一个跟上面的配置相关联

server {
    listen 443 ssl;
    server_name 域名;

	ssl_certificate     xxx.crt;
    ssl_certificate_key	xxx.key;
	ssl_session_cache   shared:SSL:1m;  
	ssl_session_timeout 5m;  
	ssl_ciphers         HIGH:!aNULL:!MD5;         
	ssl_prefer_server_ciphers  on; 

    location / {
        proxy_pass http://localhost:8100;
        fastcgi_param   HTTPS               on;
		fastcgi_param   HTTP_SCHEME         https;
    }
    #这里我是想把/1000去掉
    #这个情况下 前端请求时baseUrl需要修改为这样:https:www.xxx.com:4399/1000
    location /1000 {
		proxy_pass 代理的域名端口号;
		rewrite ^(.*)/1000(.*)$ $1$2 break;
		rewrite ^(.*)$ $1;
	}
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值