无需证书的 Nginx 代理安全

发布时间:2021-03-08 15:16

所以目前我使用 nginx 作为一个非常简单的 CORS 代理,它接收来自 javascript fetch 命令的 REST 请求和对预检检查的回答,并代理请求和回答。代理可以通过本地网络中的某个 localhost http 地址访问,然后它将请求发送到某个全局 https 地址。

然而,nginx 没有 ssl 的证书,这是否意味着我发送到 https 的请求像 http 一样完全未加密?

如果是这种情况,自签名证书是否足够,是否需要任何不同的配置?

发送提取的 javascript 是否也必须来自 https 网站?

这里是 CORS 代理的 nginx.conf。 localhost:1234 是发送 REST 请求的网站。

 server{
      listen 444;
      server_name localhost;

      location /test{
        if ($request_method = 'OPTIONS') {
          add_header 'Origin' 'localhost:1234' always;
          add_header 'Access-Control-Allow-Origin' '*' always;
          add_header 'Access-Control-Allow-Credentials' 'true' always;
          add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
          add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
          return 200;
        }

        proxy_pass https:some_api.com/;
        proxy_set_header Origin http://localhost:1234;
        proxy_hide_header Access-Control-Allow-Origin;
        add_header Access-Control-Allow-Origin $http_origin;
      }
    }
回答1