SSL证书部署,“自定义”任何“端口”或“域名”变https

我们先在server里面打上88的端口号,

然后start nginx启动监听一个服务88,让index.html的网页能在本地以:localhost:88,运行出这个网页,
此时如果你的域名是:http://www.xxx.com的话,你就可以用http://www.xxx.com:88在外部访问这个网页。
此时,你想把http://www.xxx.com,变成https://www.xxx.com的话,那么就跟着我往下走。
第一步:
我们想把腾讯云或者阿里云购买ssl证书后,只需要取这两个,

然后在下面再建立一个server,里面把如下图的信息打上,其中listen里面的80你可以换成你想要的任意端口,proxy_pass:这里右边填的是你监听的启动服务的端口,也就是我这里图一里面的那个端口,然后这里的listen 80 ssl 是填你在外网要访问的端口。


最后用nginx -t  如果显示的是这样说明成功了:


最后你就可以在外网用https访问了,
最后结果如下:

在互联网变https了,




最后附上整体代码:
 


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen      88;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #



    # HTTPS server
    #

	server {
        listen       80 ssl;
        server_name    www.hahaha.top;
    
        ssl_certificate       hahaha.top_bundle.pem;
        ssl_certificate_key   hahaha.top.key;    
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
    
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
    
        location / {
            # root   E:\\transcalpfront;
            # index  index.html index.htm index.php;
			proxy_pass http://hahaha.top:88;     # spring boot 项目的端口号
            
            # 固定写法-------------
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-Port $server_port;
        }

               
        }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大大散户

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值