import axios from 'axios'; import router from "@/router"; const request = axios.create({ baseURL: '/api', // 使用相对路径,Nginx代理请求到后端 timeout: 10000 }) // request 拦截器 request.interceptors.request.use(config => { config.headers['Content-Type'] = 'application/json;charset=utf-8'; let user = localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user')) : null //如果user存在就在请求头中设置token if (user) { config.headers['token'] = user.token; } return config }, error => { return Promise.reject(error) }); // response 拦截器 request.interceptors.response.use( response => { let res = response.data; // 如果是返回的文件 if (response.config.responseType === 'blob') { return res } // 兼容服务端返回的字符串数据 if (typeof res === 'string') { res = res ? JSON.parse(res) : res } //当权限验证不通过时直接弹出 if (res.code === '401') { localStorage.removeItem('user') router.push('/login') } return res; }, error => { console.log('err' + error) return Promise.reject(error) } ) export default request
touch /usr/front/logs/nginx_access.log chmod 666 /usr/front/logs/nginx_access.log touch /usr/front/logs/nginx_error.log chmod 666 /usr/front/logs/nginx_error.log
# 使用NGINX官方镜像作为基础镜像 FROM nginx:latest # 设置作者信息 LABEL maintainer="作者名 <邮箱>" # 创建日志目录并设置权限 RUN mkdir -p /var/log/nginx && \ touch /var/log/nginx/nginx_access.log && \ touch /var/log/nginx/nginx_error.log && \ chown -R nginx:nginx /var/log/nginx && \ chmod 755 /var/log/nginx && \ chmod 644 /var/log/nginx/nginx_access.log && \ chmod 644 /var/log/nginx/nginx_error.log # 创建 Vue 项目目录 RUN mkdir -p /usr/share/nginx/html # 复制项目文件到NGINX默认的网站目录 COPY ./front_vue /usr/share/nginx/html # 复制自定义NGINX配置文件 COPY nginx.conf /etc/nginx/nginx.conf # 暴露NGINX的HTTP端口(默认为80) EXPOSE 80 # 启动NGINX CMD ["nginx", "-g", "daemon off;"]
sudo mkdir -p /usr/front/vue/cert
events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; client_max_body_size 50m; client_body_buffer_size 10m; client_header_timeout 1m; client_body_timeout 1m; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_comp_level 4; gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; gzip_vary on; server { listen 443 ssl; server_name 服务器域名; ssl_certificate /etc/nginx/cert/server.crt; ssl_certificate_key /etc/nginx/cert/server.key; ssl_session_timeout 5m; ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA'; ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers off; # 配置 Nginx 记录访问日志和错误日志 access_log /var/log/nginx/nginx_access.log; error_log /var/log/nginx/nginx_error.log; location / { root /usr/share/nginx/html/front_vue; index index.html index.htm; try_files $uri $uri/ /index.html; } location ^~ /api/ { proxy_pass https://服务器IP:8080/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } server { listen 80; server_name 服务器域名; rewrite ^(.*)$ https://$host$1 permanent; } }
# 1进入目录 cd /usr/front/vue # 2构建镜像 docker build -t front_vue . # 3运行容器 docker run --name front_nginx --restart=always -p 80:80 -p 443:443 -d \ -v /usr/front/vue/nginx.conf:/etc/nginx/nginx.conf \ -v /usr/front/vue/front_vue:/usr/share/nginx/html/front_vue \ -v /usr/front/logs/nginx_access.log:/var/log/nginx/nginx_access.log \ -v /usr/front/logs/nginx_error.log:/var/log/nginx/nginx_error.log \ -v /usr/front/vue/cert:/etc/nginx/cert \
server: port: 8080 ssl: enabled: true # 证书类型一 key-store: classpath:xxx.pfx key-store-password: xxx # 填写keystorePass.txt文件内容 key-store-type: PKCS12 # 证书类型二 key-store: classpath:xxx.jks key-store-password: xxx # 填写keystorePass.txt文件内容 key-store-type: jks
springboot配置https接口使用的ssl整数是使用jks的还是pfx的?
在Spring Boot中,可以使用Java KeyStore(JKS)或PKCS#12文件(PFX)来配置应用程序的HTTPS。这两者都是用于存储加密密钥和证书的流行格式。
用途: JKS文件配置Spring Boot应用程序的SSL/TLS。
server: port: 8080 # 配置https接口 ssl: enabled: true key-store: classpath:keystore.jks key-store-password: 密钥库密码 key-store-type: jks
server: port: 8080 # 配置https接口 ssl: enabled: true key-store: classpath:keystore.pfx key-store-password: xxx key-store-type: PKCS12
keytool -importkeystore -srckeystore keystore.jks -destkeystore keystore.pfx -srcstoretype JKS -deststoretype PKCS12
keytool -importkeystore -srckeystore keystore.pfx -destkeystore keystore.jks -srcstoretype PKCS12 -deststoretype JKS
上一篇:SpringMVC拦截器