nginx配置https,vue+springboot前后端分离项目

编辑/etc/nginx/sites-enabled/default文件

server {

		listen 80;
        server_name www.abc.com  # 域名信息
        index index.html;

		# vue项目地址,直接放在根路径
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                root /home/ubuntu/abc-web/dist;  # vue项目的dist文件路径
                try_files $uri $uri/ /index.html;
                index index.html;
        }

    	# springboot项目访问前缀,做服务器映射,同时要在springboot里面配置前缀,否则请求处理会出错
        location /abc-api {
            #是监听的端口默认访问的地址,这里如果没有做tomcat的转发则会进入nginx的html目录下的index.html
            root   html;

            #这里是编写监听到的请求所转发的端口号,即tomcat端口
            proxy_pass http://localhost:4008;
            #Proxy Settings;
            #proxy_redirect off;
            #proxy_set_header Host $host;
            #proxy_set_header X-Real-IP $remote_addr;
            #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            #设置nginx 的默认显示页
            index  index.html index.htm;

        }

        location @router {
                rewrite ^.*$ /index.html last;
        }


        listen 443;
        ssl on;
        #证书,填写证书保存地址
        ssl_certificate      /etc/nginx/cert.pem;
        #私钥,填写密钥保存地址
        ssl_certificate_key  /etc/nginx/key.pem;

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

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

springboot配置前缀(yml文件),与nginx代理的相对路径相同,否则拦截器会错误拦截

server:
  servlet:
    context-path: /abc-api
  port: 4008

配置完成后,重启服务

service nginx force-reload		# 重启nginx
systemctl status nginx.service # 查看服务

ssl证书申请
ssl证书配置相关内容

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值