本篇主要记录vue项目,通过nginx实现https部署的免费方案。主要参考步骤和关键点如下所示。
一、生成证书
进入nginx安装目录# 进入nginx目录[root@hecs-402944 nginx]# cd /etc/nginx/[root@hecs-402944 nginx]# lsconf.d fastcgi.conf fastcgi_params koi-utf mime.types nginx.conf scgi_params uwsgi_params win-utfdefault.d fastcgi.conf.default fastcgi_params.default koi-win mime.types.default nginx.conf.default scgi_params.default uwsgi_params.default
创建ssl文件目录# 创建ssl目录[root@hecs-402944 nginx]# mkdir ssl[root@hecs-402944 nginx]# cd ssl
生成server.key,需要设置两次密码[root@hecs-402944 ssl]# openssl genrsa -aes256 -out server.key 2048Generating RSA private key, 2048 bit long modulus...........................................................+++................................................................................................+++e is 65537 (0x10001)Enter pass phrase for server.key:Verifying - Enter pass phrase for server.key:
生成无密码的server.key# 生成无密码的server.key[root@hecs-402944 ssl]# openssl rsa -in server.key -out server.keyEnter pass phrase for server.key:writing RSA key[root@hecs-402944 ssl]# lsserver.key
创建服务器证书的申请文件 server.csr此处需要填写具体内容,国家、省份、城市、公司、行业、网站、邮箱等,后面的两次密码直接回车就好。 [root@hecs-402944 ssl]# openssl req -new -key server.key -out server.csrYou are about to be asked to enter information that will be incorporatedinto your certificate request.What you are about to enter is what is called a Distinguished Name or a DN.There are quite a few fields but you can leave some blankFor some fields there will be a default value,If you enter '.', the field will be left blank.-----## 国家Country Name (2 letter code) [XX]:CN## 省份State or Province Name (full name) []:heilongjiang## 城市Locality Name (eg, city) [Default City]:haerbin## 公司Organization Name (eg, company) [Default Company Ltd]:xxxxxxx## 行业Organizational Unit Name (eg, section) []:IT## 网站Common Name (eg, your name or your server's hostname) []:www.xxxxxxx.com## 邮箱Email Address []:xxxxxx@xxxxxx.com.cnPlease enter the following 'extra' attributesto be sent with your certificate request## 两次回车A challenge password []:An optional company name []:[root@hecs-402944 ssl]# ll总用量 8-rw-r--r-- 1 root root 1082 5月 13 09:15 server.csr-rw-r--r-- 1 root root 1679 5月 13 09:11 server.key
生成crt证书文件server.crt# 生成crt证书文件server.crt[root@hecs-402944 ssl]# openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 3650Signature oksubject=/C=CN/ST=heilongjiang/L=haerbin/O=dongfangtongwangxin/OU=IT/CN=www.tongtech.com/emailAddress=weirx@mvtech.com.cnGetting Private key
二、nginx配置前端项目使用nginx部署,所以我们采用nginx爆率443端口,开启ssl。 server { listen 443 ssl http2 default_server; listen [::]:443 ssl http2 default_server; ssl on; ssl_certificate "/etc/nginx/ssl/server.crt"; ssl_certificate_key "/etc/nginx/ssl/server.key"; ssl_session_cache shared:SSL:1m; ssl_session_timeout 10m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; server_name _; include /etc/nginx/default.d/*.conf; root /opt/vue/dist; gzip_static on; location / { proxy_pass http://localhost:13000; } # 支持websocket的配置项 location /websocket { proxy_pass http://localhost:13000; # WebScoket Support proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } }
三、修改vue配置文件项目使用qiankun框架,分为主工程和子工程,所以我们需要修改在主工程当中的子工程配置,主要是访问的ip地址。 修改.env文件,在使用http时是需要配置ip+端口的,修改为https直接使用ip即可。 #开发环境env配置NODE_ENV=productionVUE_APP_SYSTEM_URL=//172.16.3.30/systemVUE_APP_COMPONENTS_URL=//172.16.3.30/componentsVUE_APP_API_BASIC_URL=//172.16.3.30/basicVUE_APP_SOCKETURL = 'wss://172.16.3.29' 如上所示,需要将websocket的请求地址由ws修改为wss,否则会报错。
总结 下载地址: 使用docker安装部署NextCloud私人网盘的方法步骤 Docker-swarm快速搭建redis集群的方法步骤 |