如果你搞个网站要http访问又要https访问咋个搞?

createh514小时前技术教程3

实际工作中不知道你遇没遇到这种问题:

  1. 客户要求微信公众号菜单的配置链接采用https访问
  2. 微信的接口对接自己服务器采用的是http访问
  3. 然后只给了一个端口8088

这种能不能实现http能够访问到服务内容,https也能够访问到服务内容呢?

我请教下了deepseek来做这个事情,它告诉我:

  1. 在中间件上进行配置8088端口
  2. 在中间件上如果使用的http转发全部重定向到https

这样问题又来了,我的https是放在ng中间件上面的,我的服务器只支持http服务

而且8088在https和http中只能选择一个

无奈,我只能多搞一个端口8089于是就成了下面这样


为什么会这样搞这么复杂,因为有部分必须搞http访问,如果用https访问就会报错http->https问题。

最后附上配置:

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;

server {

	listen 8089;
        server_name      -; #不能说
				ssl on; #必须打开不然会报错
        ssl_certificate      E:\\www\wx\\nginx-1.5.71\conf\*.crt;
        ssl_certificate_key  E:\\www\wx\\nginx-1.5.71\conf\*.key;


	#		ssl_session_cache shared:SSL:500m;
    		ssl_session_timeout  10m;
    		ssl_ciphers HIGH:!aNULL:!MD5;
    		ssl_prefer_server_ciphers on; 
				gzip on;
        gzip_min_length 1k;
        gzip_buffers 4 16k;
        #gzip_http_version 1.0;
        gzip_comp_level 2;
        gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
        gzip_vary off;
        gzip_disable "MSIE [1-6]\.";
        location ~* \.(css|js|png|jpg|jpeg|gif|gz|svg|mp4|ogg|ogv|webm|htc|xml|woff)$ {
            root  E:/www/wx/H5WX;
            add_header Cache-Control max-age=604800;
        }
	  location / {
            root   E:/www/wx/H5WX;
            add_header  Cache-Control  max-age=no-cache;
            index  index.html index.htm;
        }
        location /CstService.asmx{
            proxy_pass http://127.0.0.1/CstService.asmx;
        }		
}
  
  server {
    listen 8088;
    server_name -;  # 不可说

    location / {
        proxy_pass http://127.0.0.1/CstService.asmx;  # 转发到本机8080
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
}


相关文章

nginx 代理转发 http https 基本用法

nginx 配置http最简单的用法;server{ # 监听的端口 listen 80; # 绑定的域名,多个用空格分开即可。 server_name prvt.c...

nginx 服务器配置https时如何重定向http

为了网络访问的安全性,https被更多的网站所使用,现在开发App,微信小程序都固定为使用https的访问,让访问更安全,但同时也得处理http请求,使它重定向,方便官网的访问。nginx 服务器配置...

nginx配置https详解

要在Nginx上配置HTTPS,需要进行以下步骤:获取证书和密钥文件 在使用HTTPS之前,需要先获取SSL证书和密钥文件。可以通过购买证书或者使用自签名证书来获取,证书和密钥文件可以通过各种方式获取...

Nginx: 最常见的 2 种 http to https 跳转场景

Nginx: 最常见的 2 种 http to https 跳转场景建议点击 查看原文 查看最新内容。原文链接: https://typonotes.com/posts/2023/08/28/ngin...

nginx配置https的详细流程

1、下载SSL证书2、两个证书放在cert目录上然后放到nginx 与nginx.conf同目录下3、去nginx解压目录下执行./configure --with-http_ssl_module如果...