nginx将http重定向到localhost上的https

时间:2017-10-13 11:48:10

标签: redirect nginx https localhost

我在本地测试nginx作为反向代理

我想将通配符子域http重定向到https

子域名在应用程序中以编程方式处理

    server {
        listen         80;
        server_name ~^(.*)\.localhost$;
        return 301 https://$server_name$request_uri;
    }

    server {
        listen  443 ssl;
        gzip on;
        gzip_comp_level 6;
        gzip_vary on;
        gzip_min_length  1000;
        gzip_proxied any;
        gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
        gzip_buffers 16 8k; 

        server_name ~^(.*)\.localhost$;
        # SSL Certs
        ssl_certificate /path/to/server.crt;
        ssl_certificate_key /path/to/server.key;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

        location / {
            proxy_pass http://localhost:3333;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
    }

直接从Chrome访问https可以正常工作 访问http确实没什么,甚至没有页面刷新

0 个答案:

没有答案