HTTP--http之https(九)

生成公鑰和私鑰

用git運行如下命令,而後一直按回車node

openssl req -x509 -newkey rsa:2048 -nodes -sha256 -keyout localhost-privkey.pem -out localhost-cert.pem

clipboard.png

目錄結構

clipboard.png

文件內容

test.conf
server {
        listen       443;
        server_name  test.com;

        ssl on;
        ssl_certificate_key ../certs/localhost-privkey.pem;
        ssl_certificate ../certs/localhost-cert.pem;

        location / {
            proxy_cache my_cache;
            proxy_pass http://127.0.0.1:8888;
            proxy_set_header Host $host;
        }
    }

運行本地服務

test.com

clipboard.png

https://test.com

clipboard.png

clipboard.png

test.com重定向到https://test.com

test.conf
proxy_cache_path cache levels=1:2 keys_zone=my_cache:10m;

    server {
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name test.com;
        return 302 https://$server_name$request_uri;
    }

    server {
        listen       443;
        server_name  test.com;

        ssl on;
        ssl_certificate_key ../certs/localhost-privkey.pem;
        ssl_certificate ../certs/localhost-cert.pem;

        location / {
            proxy_cache my_cache;
            proxy_pass http://127.0.0.1:8888;
            proxy_set_header Host $host;
        }
    }

clipboard.png

clipboard.png

相關文章
相關標籤/搜索