实际工作中不知道你遇没遇到这种问题:
- 客户要求微信公众号菜单的配置链接采用https访问
- 微信的接口对接自己服务器采用的是http访问
- 然后只给了一个端口8088
这种能不能实现http能够访问到服务内容,https也能够访问到服务内容呢?
这里使用的中间件是ngnix
我请教下了deepseek来做这个事情,它告诉我:
- 在中间件上进行配置8088端口
- 在中间件上如果使用的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;
}
}
}