BT宝塔Nginx 网站配置文件http和https问题

问题遇到的现象和发生背景

原本我是想解决ajax https 跨域请求http 问题的,结果发现https跨域请求http几乎无解。如此一来,我只能退而求其次了。

问题相关代码,请勿粘贴截图

img

运行结果及报错内容

img

我的解答思路和尝试过的方法

因为我使用的是泛域名SLL证书,所以每个子域名都绑定了一个业务。但是所有业务都在同一个站点里。

那么我现在只有其中一个业务:panel需要使用跨域,如以上问题发生背景。https跨域请求http几乎无解,但是http却可以跨域请求http和https。

我想要达到的结果

所以我想强制panel采用http访问,其他业务域名正常强制https访问。该怎么修改网站配置?

可以的;

你把panel的配置优先处理即可。

https://zhidao.baidu.com/question/1889046735233221068.html

https://blog.csdn.net/qq_27229113/article/details/90698502

参考:

  server {
        listen 443 ssl;
        ssl on;
        server_name  二级域名;#例如:www.baidu.com
        #charset koi8-r;
        ssl_certificate /usr/local/nginx-1.8.1/cert/SSL证书.pem;
        ssl_certificate_key /usr/local/nginx-1.8.1/cert/SSL证书.key;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        charset   utf-8;
        location / {
            proxy_pass   http://127.0.0.1:8080;#反向代理到后端服务器
            index  index.html index.htm;
        }
 
       }
       
    server {
        listen       80;
        server_name  二级域名;#例如:www.baidu.com
        #charset koi8-r;
        #access_log  logs/host.access.log  main;  
        rewrite ^(.*) https://$server_name$1 permanent;#80端口请求都强制跳转到443端口进行处理
        charset   utf-8;
        location / {        
            index  index.html index.htm;
        }
 
       }