本地基于nginx配置https域名访问本地web工程( node+webpack+vue、localhost:8080)的方法

458 阅读1分钟
  1. nginx配置如下
worker_processes  1;

events {
    worker_connections  1024;
}

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

    sendfile        on;
    keepalive_timeout  65;

    server {
		listen     443 ssl;
		client_max_body_size 10240m;  # 录像及文件上传大小限制
		keepalive_timeout  1000;
		client_header_timeout 1000;                 #等待客户端的头部超时时间
		client_body_timeout 1000;                   #等待客户端的主体超时时间
		server_name 127.0.0.1;
		
		ssl_certificate D:/tools/nginx-1.14.2/nginx-1.14.2/conf/ainnovation.com-2021.pem; #加密证书文件提前生成
		ssl_certificate_key D:/tools/nginx-1.14.2/nginx-1.14.2/conf/ainnovation.com-2021.key; #加密证书文件提前生成

		location / {
			proxy_pass http://127.0.0.1:8080/; #直接配置为http://localhost:8080/会特别慢
		}
	}
}
  1. host文件配置如下
127.0.0.1     test.com
  1. 重启nginx,浏览器访问https://test.com 即可