Vue(Vite)設定Content-Security-Policy支援

vue3支援csp方法只需要設定vite.config.js :

import { fileURLToPath, URL } from 'node:url'

import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'


// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  // eslint-disable-next-line no-undef
  const env = loadEnv(mode, process.cwd());
  // this might be needed in Dev mode
  const nonce = mode === "development" ? "nonce" : "{SERVER-GENERATED-NONCE}";

  return {
    plugins: [
      vue(),

    ],
    html: {
      cspNonce: `${nonce.toString()}`
    },
    // eslint-disable-next-line no-undef
    base: env.VITE_WORKDIR
    ,
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
    server: {
      headers: {
        'Content-Security-Policy': `default-src 'self'; script-src 'self' 'nonce-${nonce.toString()}'; style-src   'nonce-${nonce.toString()}'; font-src 'self' data:; img-src 'self'; frame-src 'self';form-action none  `,
      },
     
       
      }
    }
  }
})

Mariadb Tomcat Docker environment

This is a docker-compose yml,Integrated Mariadb、phpMyAdmin、tomcat Docker

How to start

  • install docker-ce and docker-compose
  • change to project directory to build and run docker
    sudo docker-compose up -d --build
  • use phpMyAdmin restore database (options)
  • build project war file and put to tomcat-webapps directory
  • browse http://yourip:8080/warFileName

docker information

  • mariadb:latest
  • phpmyadmin/phpmyadmin:latest
  • tomcat:8.5.49-jkd8-openjdk

default information

  • tomcat manager account and password admin / mypassword112233
  • mariadb root default password myadmin123
  • phpMyAdmin default port 8088
  • tomcat default port 8080 ;AJP port 8009
  • tomcat workspace is tomcat-webapps
Read More

GitHub Maven專案自動編譯成war檔

https://github.com/catyku/AutoMavenBuild

Github的maven專案(私有)可以直接下載然後編譯成war deploy檔

需要安裝docker-ce

  • 取得及設定github ssh key可以參考以下這篇

https://help.github.com/en/enterprise/2.17/user/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

  • 修改及設定使用者名稱及專案名稱 -> run.sh (記得mvn -P 的build config也要改成相對應的)
  • 產生docker image tag名稱為maven:project ,可自行修改
  sudo docker build -t maven:project .
  • github下載及編譯打包專案
Read More

docker tomcat with manager html

範例來源

修改 FROM tomcat:8.5.49-jdk8-openjdk
加入 tomcat-users.xml 跟 manager的context.xml來取得manager/html存取權限

tomcat-users.xml為登入資訊
context.xml則管理存取ip等資訊

環境

openjdk 1.8
tomcat 8.5

編譯及執行

sudo docker build ./ -t yourname

and run

sudo docker run -d  -p 8080:8080 --name tomcat  catyku/tomcat:8.5-jre8

Read More

使用logrotate分割tomcat catalina.out

每天自動分割catalina.out檔,免得太大變成無法開啟的log檔

sudo nano /etc/logrotate.d/tomcat
#tomcat 可以自己取
/opt/tomcat/logs/catalina.out{
copytruncate
daily
rotate 30
missingok
compress
size 16M
}

設定檔說明:

  • /opt/tomcat/logs/catalina.out log檔位置
  • daily – 每日分割
  • rotate – 最多保留30個文件(30天?)
  • compress – 壓縮文件
  • size – 當catalin.out大於16M時分割文件

手動執行方法

 /usr/sbin/logrotate /etc/logrotate.conf