Appearance
常用软件配置文件
随记
将成功的东西整理成册,就能永远成功。
收集一些常用软件的默认配置、某系统下的配置,我会将自己常用配置加进去,方便随时下载保存
有些关键配置我会直接贴出方便复制,默代表官方默认配置,否则代表我有添加自己常用的配置
maven
就配置阿里源还有本地仓库,linux和mac可以用一个,该本地仓库地址就行了
关键配置
xml
<settings>
<!--需要改成自己的maven的本地仓库地址-->
<localRepository>/Users/shafulin/repository</localRepository>
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
</settings>mvnd
nginx
默windows |直nginx.conf for windwos默linux |直nginx.conf for linux- localtion配置参考
- Nginx一网打尽:动静分离、压缩、缓存、黑白名单、跨域、高可用、性能优化
前端配置
shell
location / {
alias html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}后端配置
后台接口反向代理配置,记得location和proxy_pass路径都末尾跟上/
shell
location /server-api/ {
proxy_pass http://127.0.0.1:8080/;
}https配置
注意
cert目录在nginx目录/conf下- 1.15.x 之前配置
listen 443;ssl on;
1.15.x 之后配置listen 443 ssl
shell
server {
# 这里配置的是nginx1.15.x 之后配置
listen 443 ssl;
ssl_certificate cert/scs1676729321474_xxx.com_server.crt;
ssl_certificate_key cert/scs1676729321474_xxx.com_server.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
# 直接代理到原有http地址就行了
location / {
proxy_set_header Upgrade $http_upgrade; #此处配置 上面定义的变量
proxy_set_header Connection $connection_upgrade;
proxy_pass http://127.0.0.1;
}
}阿里云域名证书-三级域名不限定
这里玩一个花的,如果你申请的域名是阿里云的例如shafulin.com,且申请了shafulin.com一个证书,如果按照上面方法配置,那么你只能使用https://shafulin.com访问对应的http地址 如果再加上一个参数resolver dns1.hichina.com dns2.hichina.com;,完整参数如下
shell
server {
# 这里配置的是nginx1.15.x 之后配置
listen 443 ssl;
ssl_certificate cert/scs1676729321474_xxx.com_server.crt;
ssl_certificate_key cert/scs1676729321474_xxx.com_server.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
# dns域名服务商配置,使用$host需要配置resolver
resolver dns1.hichina.com dns2.hichina.com;
# resolver ns1.huaweicloud-dns.org ns1.huaweicloud-dns.net ns1.huaweicloud-dns.cn ns1.huaweicloud-dns.com; # 华为云dns服务商
# 直接代理到原有http地址就行了
location / {
proxy_set_header Upgrade $http_upgrade; #此处配置 上面定义的变量
proxy_set_header Connection $connection_upgrade;
proxy_pass http://$host;
}
}静态资源
示例:访问 服务器ip:端口/profile/1.txt,即可访问服务器/opt/files/1.txt文件
shell
location /profile/ {
# 允许 所有头部 所有域 所有方法
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Headers' '*';
add_header 'Access-Control-Allow-Methods' '*';
alias /opt/files/;
}示例:代理所有的html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css文件并设置缓存时效7天
shell
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css){
# 这里的位置就指的静态资源的地址
root /soft/nginx/static_resources;
expires 7d;
}路径重写
访问nginx服务/iam.html就相当于访问http://www.baidu.com
shell
location /iam.html {
rewrite ^/(.*)$ http://www.baidu.com;
}负载均衡
shell
# http块添加,负载均衡策略自己选
upstream myserver{
server 127.0.0.1:8080;
server 127.0.0.1:8081;
}
# http-server块添加
location / {
proxy_pass http://myserver;
}Gzip压缩
在http块内或者在单个server块
shell
#开启gzip
gzip on;
#低于1kb的资源不压缩
gzip_min_length 1k;
#压缩级别1-9,越大压缩率越高,同时消耗cpu资源也越多,建议设置在5左右。
gzip_comp_level 5;
#需要压缩哪些响应类型的资源,多个空格隔开。不建议压缩图片.
gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css;
#配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip(因为ie低版本不支持)
gzip_disable "MSIE [1-6]\.";
#是否添加“Vary: Accept-Encoding”响应头
gzip_vary on;webSocket
shell
# http块添加
map $http_upgrade $connection_upgrade {
default keep-alive; #默认为keep-alive 可以支持 一般http请求
'websocket' upgrade; #如果为websocket 则为 upgrade 可升级的。
}
# http-server块添加
# 某后台服务
location /shanxipufa-api/ {
client_max_body_size 200m;
proxy_set_header Upgrade $http_upgrade; #此处配置 上面定义的变量
proxy_set_header Connection $connection_upgrade;
proxy_pass http://127.0.0.1:38080/;
}流量复制
注意安装nginx时一定要安装
http_mirror_module这个模块, nginx 1.13.4及后续版本内置了ngx_http_mirror_module模块,安装版本注意下
参考文档
手机端/PC端共用一个地址
手机端/PC端共用一个地址,手机端自动导航到手机端页面
shell
# 访问pc端
location /zhongzhi-pc/ {
alias /Users/shafulin/project/deploy/zhongzhi-pc/;
index index.html index.htm;
#判断终端
if ($http_user_agent ~* '(Android|webOS|iPhone|iPod|iPad|BlackBerry)') {
set $mobile_request '1';
# 如果访问UA为移动终端类型则判断为 mobile_request=1
}
if ($http_cookie ~ 'mobile_request=full') {
set $mobile_request '';
}
if ($mobile_request = '1') {
rewrite ^/(.*)$ http://$host/zhongzhi-mobile/ redirect;
}
}
# 访问手机端
location /zhongzhi-mobile/ {
alias /Users/shafulin/project/deploy/zhongzhi-mobile/;
index index.html index.htm;
}文件服务器
shell
# 文件服务器
server {
listen 8888;
server_name localhost;
autoindex on;# 显示目录
autoindex_exact_size on;# 显示文件大小
autoindex_localtime on;# 显示文件时间
root /home/renyong/share/;
charset gbk,utf-8; # 防止中文乱码
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}nginx端口转发
shell
# 编译nginx的时候要添加stream模块 ./configure –with-stream
# 这个模块实现了网络层和传输层的的转发、代理、负载均衡等
# stream与http配置同级
stream {
server {
listen 3306;
proxy_connect_timeout 1s;
proxy_timeout 300s;
proxy_pass 192.168.8.168:3306;
# 有了这个server配置,你就可以通过代理机ip+3306端口访问内网的mysql库了
}
server {
listen 3000;
proxy_connect_timeout 1s;
proxy_timeout 300s;
proxy_pass 192.168.8.110:3000;
# 有了这个配置,你就可以直接访问代理机ip+8080端口,访问你的内网web服务了
}
}nginx携带cookie
参考文档
有些请求授权从cookie里携带参数,让前端直接发送携带cookie的请求比较难搞,后台还要添加一些跨域配置,通过nginx代理就能轻松做到
- 将原来要传到cookie属性的数据放到cookie2请求头属性
- 通过开启携带cookie配置,以及cookie请求头数据添加成功拼上Cookie
shell
# 携带cookie,将请求头里的cookie2属性当做cookie
location /yunduan-api/ {
# 这两句是关键
add_header 'Access-Control-Allow-Credentials' 'true' always;
proxy_set_header Cookie $http_cookie2;
proxy_pass https://e62580258.at.baijiayun.com/;
}端口共用
一般一个应用一个端口,但是nginx可以通过区分
server_name达到端口共用,此类做法适用于有域名的场景 本文示例nginx安装目录为/usr/local/nginx,购买域名为example.com
- 在nginx配置目录下,创建目录
conf.d
shell
mkdir -p /usr/local/nginx/conf/conf.d- 编辑
/usr/local/nginx/conf/nginx.conf配置文件,在http块添加如下配置
shell
include /usr/local/nginx/conf/conf.d/*.conf;- 新增
/usr/local/nginx/conf/conf.d/domain1.example.com.conf配置文件作为站点1配置,添加如下配置
注意
server_name要与文件名一致
shell
server {
listen 80;
# 域名1,其他三级域名同理添加
server_name domain1.example.com;
# 管理面板
location / {
client_max_body_size 2000m;
proxy_pass http://127.0.0.1:30672/;
}
error_page 404 /404.html;
location = /404.html {
# 404 页面的目录
root /usr/local/nginx/html;
}
}http强制跳转https
参考文档
- nginx将https协议反向代理到http协议请求上的实现 在
http-server-80块添加
shell
return 301 https://$host$request_uri;redis
常用配置
shell
protected-mode no # 保护模式
daemonize yes #daemonize 属性改为 yes (开机后台启动)
port 6379 # redis端口号
bind 127.0.0.1 # 默认这行被注释,代表允许谁连接,改成0.0.0.0 代表任意ip可访问
dir ./ #指定指定本地数据库存放目录
requirepass your_pwd # redis连接密码,默认被注释掉了
appendonly yes # 开启aof持久化mysql
MongoDB
- mongod.cfg
shell
systemLog:
destination: file
path: "D:/Program/mongod3.6.23/log/mongod.log"
logAppend: true
storage:
dbPath: "D:/Program/mongod3.6.23/db"
journal:
enabled: true
net:
bindIp: 127.0.0.1
port: 27017
maxIncomingConnections: 10000安装服务
shell
mongod --config "D:\Program\mongodb3.6.23\mongod.cfg" --installchfs
Nacos
vscode系列编辑器
常用设置
- 项目新建窗口打开,不要覆盖当前窗口
设置项搜索openFoldersInNewWindow ,修改值为on
settings.json
用户配置settings.json
json
{
"redhat.telemetry.enabled": true,
"files.autoSave": "afterDelay",
// 文件缩进相关配置----------------------------start
// 使用空格代替 Tab
"editor.insertSpaces": true,
// 自动检测文件已有的缩进风格(推荐开启)
"editor.detectIndentation": true,
"[yaml,yml,xml]": {
"editor.tabSize": 2,
"editor.insertSpaces": true
},
"[javascript,javascriptreact,typescript,typescriptreact]": {
"editor.tabSize": 2,
"editor.insertSpaces": true
},
"[html,vue]": {
"editor.tabSize": 2,
"editor.insertSpaces": true
},
"[java]": {
"editor.tabSize": 4,
"editor.insertSpaces": true
},
"[json,jsonc]": {
"editor.tabSize": 2,
"editor.insertSpaces": true
},
// 文件缩进相关配置----------------------------end
// jdk相关配置----------------------------start
"java.home": "D:/Program Files/Java/jdk-17.0.0.1", // 可选:显式指定 JDK(VS Code 通常能自动检测)
"java.configuration.runtimes": [
{
"name": "JavaSE-17",
"path": "D:/Program Files/Java/jdk-17.0.0.1",
"default": true
}
],
"java.compile.nullAnalysis.mode": "automatic", // 启用空值分析
"java.format.enabled": false, // 关闭内置格式化(建议用 Google Java Format 或 Eclipse Formatter)
"java.saveActions.organizeImports": true, // 保存时自动整理 imports
"java.autobuild.enabled": true, // 启用自动构建(默认已开启)
"java.debug.settings.hotCodeReplace": "auto",
// 保存时自动整理 imports
// jdk相关配置----------------------------end
// maven相关配置----------------------------start
"maven.executable.path": "D:/Program Files/apache-maven-3.9.9/bin/mvn.cmd", // 可选:指定 mvn 命令路径(Windows 用 mvn.cmd)
"maven.settingsFile": "D:/Program Files/apache-maven-3.9.9/conf/settings.xml", // 指定 Maven settings 文件
"maven.view": "hierarchical", // 项目视图:flat / hierarchical
"java.configuration.updateBuildConfiguration": "interactive",
"maven.executable.options": "-T 2C -DskipTests -U", // 传递 JVM 参数给 Maven
// maven相关配置----------------------------end
// 终端相关配置----------------------------end
// 编辑器编码(保留)
"files.encoding": "utf8",
"files.autoGuessEncoding": true,
// 终端核心配置
"terminal.integrated.defaultProfile.windows": "PowerShell",
"terminal.integrated.fontFamily": "Consolas, Microsoft YaHei, SimHei, monospace",
"terminal.integrated.encoding": "utf8",
// 普通交互终端(手动打开Ctrl+`)
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
// 必须加 -Command,才能执行chcp,>nul屏蔽输出提示
"args": ["-NoExit", "-Command", "chcp 65001 > $null"]
}
},
// 关键:调试/任务/Maven后台执行终端(你之前漏掉,乱码重灾区)
"terminal.integrated.automationProfile.windows": {
"path": "powershell.exe",
"args": ["-Command", "chcp 65001 > $null"]
},
// 全局终端环境变量,强制UTF8
"terminal.integrated.env.windows": {
"PYTHONUTF8": "1",
"JAVA_TOOL_OPTIONS": "-Dfile.encoding=UTF-8"
}
// 终端相关配置----------------------------end
}.vscode/settings.json
json
{
"terminal.integrated.defaultProfile.windows": "Git Bash", // 设置默认终端
}.vscode/launch.json
launch.json
json
{
"version": "0.2.0",
"configurations": [
// 当前工程
{
"type": "java",
"name": "Current File",
"request": "launch",
"mainClass": "${file}"
},
{
"type": "java",
"name": "外网应用",
"request": "launch",
"mainClass": "com.cosl.hris.HrisOuternetApplication",
"projectName": "cosl-oc-hris-outernet",
// jrebel参数
"vmArgs": "-agentpath:C:\\Users\\18331\\.trae-cn\\extensions\\jrebelbyperforcesoftware.jrebel-2026.2.2-universal\\agent\\jrebel\\lib\\jrebel64.dll",
"env": {
// 区分环境
"SPRING_PROFILES_ACTIVE": "outer,proxy"
}
},
{
"type": "java",
"name": "内网应用",
"request": "launch",
"mainClass": "com.cosl.hris.HrisOuternetApplication",
"projectName": "cosl-oc-hris-outernet",
"console": "internalConsole", // 内置控制台,注意这个和jrebel有冲突
}
]
}