前端vue部署到nginx并且配置https安全证书全流程

news2024/10/6 7:50:13
        说明一下: 本人原本使用的是docker安装nginx通过挂载实现部署,但是出现了很多bug(例如部署安全证书后还是无法访问),所以困扰了很久,最后改为本地安装nginx,最终在不懈的努力下终于按照好了,特此记录一下。

        一:整个流程:

              1. 将前端项目打包,会生成dist文件(同时不要忘了修改调用后台的ip)

              2. 安装nginx(本地安装,非docker),然后将dist下的文件放入nginx的html目录下

              3. 配置nginx的配置文件

              4. 安装证书(ssl)

            安装nginx,ssl参考:https://blog.csdn.net/oYingJie1/article/details/127700897

            下载及安装ssl参考:https://blog.csdn.net/qq_42320934/article/details/120655799

        二: 附上关键代码及说明

                1.nginx的配置文件

#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       80;
        server_name  localhost;
	   #将所有HTTP请求通过rewrite指令重定向到HTTPS。
	   rewrite ^(.*)$ https://$host$1;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

        location /undefined/  {
        proxy_pass http://s11.s100.vip:35053;
        proxy_redirect default;
	   rewrite ^/undefined/(.*) /$1 break;
    	   }

        #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
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

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


    # HTTPS server
    #
    server {
        listen       443 ssl;
        server_name  localhost;

        ssl_certificate      cert.pem;
        ssl_certificate_key  cert.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

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

        location /undefined/  {
        proxy_pass http://s11.s100.vip:35053;
        proxy_redirect default;
	   rewrite ^/undefined/(.*) /$1 break;
    	   }
    }

}
        2. 以前docker配置的文件

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;

    server {
    listen       80;
    listen  [::]:80;
    server_name  www.slgstu.top;
	#将所有HTTP请求通过rewrite指令重定向到HTTPS。
#    rewrite ^(.*)$ https://$host$1;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    
    location /undefined/  {
        proxy_pass http://s11.s100.vip:35053;
        proxy_redirect default;
	   rewrite ^/undefined/(.*) /$1 break;
    }


    #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   /usr/share/nginx/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;
    #}
}

server {
     #HTTPS的默认访问端口443。
     #如果未在此处配置HTTPS的默认访问端口,可能会造成Nginx无法启动。
     listen 443 ssl;
     
     #填写证书绑定的域名
     server_name www.slgstu.top;
 
     #填写证书文件名称
     ssl_certificate cert/www.slgstu.top.cer;
     #填写证书私钥文件名称
     ssl_certificate_key cert/www.slgstu.top.key;
 
     ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;
 
     # 指定密码为openssl支持的格式
     ssl_protocols  SSLv2 SSLv3 TLSv1.2;
 
     ssl_ciphers  HIGH:!aNULL:!MD5;  # 密码加密方式
     ssl_prefer_server_ciphers  on;   # 依赖SSLv3和TLSv1协议的服务器密码将优先于客户端密码
 
 
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
}
    
}

                3.说明下nginx的文件作用

                        cert:放https证书的两个文件

                        conf: nginx的一些配置文件,主要还是使用nginx.conf

                        html:默认的话nginx会加载html文件下的index.html

                        log:查看成功与错误日志

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/786758.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

H5页面 卡片 分享朋友圈和好友

项目背景: 前后端分离: 后端: C# 开发 前端: 就是微信中打开的 H5页面 纯 H5 业务流程: 因为在 h5 中实现 卡片分享 的一个字段, 需要后端 访问 腾讯API 生成,所以整个分享结构和流程就比较长&#xff…

Stable diffusion 和 Midjourney 怎么选?

通过这段时间的摸索,我将和你探讨,对普通人来说,Stable diffusion 和 Midjourney 怎么选?最重要的是,学好影视后期制作对 AI 绘画创作有哪些帮助?反过来,AI 绘画对影视后期又有哪些帮助&#xf…

Python案例变量实践

编程:非常需要实践,不要光看,一定要动动手 什么是程序? 数据结构算法 数据结构:存储和使用数据的方式 算法:解决问题的步骤 解决一个问题的时候,分析问题,设计算法,编…

网约车服务端线上流量巡检与测试验收技术

摘要 滴滴网约车致力于让出行更美好,平台为司乘提供良好体验的同时承载了广大群众的出行服务,致使我们对服务可用性的要求较高。更快地发现系统bug,可以让更少的司乘用户受影响。发现bug的能力更精细,可以让一些不易被用户感知但…

2D坐标系下的点的转换矩阵(平移、缩放、旋转、错切)

文章目录 1. 平移 (Translation)2. 缩放 (Scaling)3. 旋转 (Rotation)4. 错切 (Shearing)5. 镜像 (Reflection) 1. 平移 (Translation&#xff09…

Nautilus Chain:主权模块化区块链的早期实践

“Nautilus Chain 是目前行业内首个以模块化的方式构建的主权 Layer3 区块链系统,其也是 Celestia 模块化 Layer0 体系下最早的印证者,现在 Nautilus Chain 主网正式上线,揭示着模块化区块链正在从早期的理论阶段走向实践。” Celestia &…

Godot 4 源码分析 - 获取属性信息

在管道通信基础上,可进行宿主程序与Godot的双向通信。 先拿属性信息试试手。 DrGraph端 static UnicodeString command "Book.position"; if (InputQuery("输入窗口", "请输入待获取的属性信息", command)) {TDrStream_Get drGet…

5.10 Bootstrap 按钮(Button)插件

文章目录 Bootstrap 按钮(Button)插件加载状态单个切换复选框(Checkbox)单选按钮(Radio)用法选项方法 Bootstrap 按钮(Button)插件 按钮(Button)在 Bootstrap…

forEach遍历访问set造成的无限循环问题

抛出问题 先给出一段代码,我们创建了一个集合set,它里面有一个元素数字1和2,接着我们调用forEach方法来遍历该集合。在遍历函数中,首先调用delete方法删除数字1,再执行了某些业务操作后紧接着调用add方法将数字1加回&…

Linux系统root用户切换及密码修改

天行健,君子以自强不息;地势坤,君子以厚德载物。 每个人都有惰性,但不断学习是好好生活的根本,共勉! 文章均为学习整理笔记,分享记录为主,如有错误请指正,共同学习进步。…

2023 年第二届钉钉杯大学生大数据挑战赛 初赛 B:美国纽约公共自行车使用量预测分析 问题二Python代码分析

2023 年第二届钉钉杯大学生大数据挑战赛 初赛 B:美国纽约公共自行车使用量预测分析 问题二 相关链接 【2023 年第二届钉钉杯大学生大数据挑战赛】 初赛 B:美国纽约公共自行车使用量预测分析 问题一Python代码分析 【2023 年第二届钉钉杯大学生大数据挑…

面试—Redis相关

文章目录 一、概述二、缓存1、缓存穿透2、缓存击穿3、缓存雪崩4、双写一致性5、持久化6、数据过期策略7、数据淘汰策略 三、分布式锁四、其它面试题1、主从复制2、哨兵3、分片集群结构4、I/O多路复用 一、概述 使用场景: Redis的数据持久化策略有哪些什么是缓存穿透…

[PyTorch][chapter 44][RNN]

简介 循环神经网络(Recurrent Neural Network, RNN)是一类以序列(sequence)数据为输入,在序列的演进方向进行递归(recursion)且所有节点(循环单元)按链式连接的递归神经网…

leetcode 面试题 判定是否互为字符重排

⭐️ 题目描述 🌟 leetcode链接:判定是否互为字符重排 思路: 两个字符串的每个字母和数量都相等。那么 s2 一定可以排成 s1 字符串。 代码: bool CheckPermutation(char* s1, char* s2){char hash1[26] {0};char hash2[26] {…

Python深度学习“四大名著”之一【赠书活动|第二期《Python机器学习:基于PyTorch和Scikit-Learn》】

近年来,机器学习方法凭借其理解海量数据和自主决策的能力,已在医疗保健、 机器人、生物学、物理学、大众消费和互联网服务等行业得到了广泛的应用。自从AlexNet模型在2012年ImageNet大赛被提出以来,机器学习和深度学习迅猛发展,取…

不知道零基础小白拥有一个黑客梦有没有机会能够实现

01.简单了解一下网络安全 说白了,网络安全就是指网络系统中的数据受到保护不被破坏。而我们从事网络信息安全工作的安全工程师,主要工作当然是设计程序来维护网络安全了。 网络安全工程师是一个统称,还包含很多职位,像安全产品工…

【代码随想录day19】从前序与中序遍历序列构造二叉树

题目 思路 使用递归建树,流程如下: 取出后序节点创建新树的节点 找到新树的节点在中序中的索引 分割中序序列 分割后序序列 继续递归建立整颗新树 # Definition for a binary tree node. # class TreeNode: # def __init__(self, val0, leftN…

spring-cloud-alibaba——nacos-server搭建

前言:组件版本关系,官方:组件版本关系 1,nacos-server搭建(windows环境),下载地址nacos 选择对应的版本,这里以目前最新版2.2.3为例子,下载后解压 单机模式 修改\nacos-server-2.2.3\nacos\bin\startup.c…

【ribbon】Ribbon的使用与原理

负载均衡介绍 负载均衡(Load Balance),其含义就是指将负载(工作任务)进行平衡、分摊到多个操作单元上进行运行,例如FTP服务器、Web服务器、企业核心应用服务器和其它主要任务服务器等,从而协同…

【全方位解析】如何获取客户端/服务端真实 IP

一、应用场景 1.比如在投票系统开发中,为了防止刷票,我们需要限制每个 IP 地址只能投票一次 2.当网站受到诸如 DDoS(Distributed Denial of Service,分布式拒绝服务攻击)等攻击时,我们需要快速定位攻击者…