常用软件配置文件
收集一些常用软件的默认配置、某系统下的配置,我会将自己常用配置加进去,方便随时下载保存
有些关键配置我会直接贴出方便复制,默代表官方默认配置,否则代表我有添加自己常用的配置
# maven
就配置阿里源还有本地仓库,linux和mac可以用一个,该本地仓库地址就行了
# 关键配置
<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>
2
3
4
5
6
7
8
9
10
11
12
# mvnd
# nginx
默windows |直nginx.conf for windwos默linux |直nginx.conf for linux- localtion配置参考 (opens new window)
- Nginx一网打尽:动静分离、压缩、缓存、黑白名单、跨域、高可用、性能优化 (opens new window)
# 前端配置
location / {
alias html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
2
3
4
5
# 后端配置
后台接口反向代理配置,记得location和proxy_pass路径都末尾跟上/
location /server-api/ {
proxy_pass http://127.0.0.1:8080/;
}
2
3
# https配置
注意
cert目录在nginx目录/conf下- 1.15.x 之前配置
listen 443;ssl on;
1.15.x 之后配置listen 443 ssl
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;
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 阿里云域名证书-三级域名不限定
这里玩一个花的,如果你申请的域名是阿里云的例如shafulin.com,且申请了shafulin.com一个证书,如果按照上面方法配置,那么你只能使用https://shafulin.com访问对应的http地址
如果再加上一个参数resolver dns1.hichina.com dns2.hichina.com;,完整参数如下
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;
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 静态资源
示例:访问 服务器ip:端口/profile/1.txt,即可访问服务器/opt/files/1.txt文件
location /profile/ {
# 允许 所有头部 所有域 所有方法
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Headers' '*';
add_header 'Access-Control-Allow-Methods' '*';
alias /opt/files/;
}
2
3
4
5
6
7
示例:代理所有的html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css文件并设置缓存时效7天
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css){
# 这里的位置就指的静态资源的地址
root /soft/nginx/static_resources;
expires 7d;
}
2
3
4
5
# 路径重写
访问nginx服务/iam.html就相当于访问http://www.baidu.com
location /iam.html {
rewrite ^/(.*)$ http://www.baidu.com;
}
2
3
# 负载均衡
# http块添加,负载均衡策略自己选
upstream myserver{
server 127.0.0.1:8080;
server 127.0.0.1:8081;
}
# http-server块添加
location / {
proxy_pass http://myserver;
}
2
3
4
5
6
7
8
9
# Gzip压缩
在http块内或者在单个server块
#开启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;
2
3
4
5
6
7
8
9
10
11
12
# webSocket
# 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/;
}
2
3
4
5
6
7
8
9
10
11
12
13
# 流量复制
注意安装nginx时一定要安装
http_mirror_module这个模块, nginx 1.13.4及后续版本内置了ngx_http_mirror_module模块,安装版本注意下
参考文档
- Nginx流量复制 (opens new window)
- Nginx流量拷贝ngx_http_mirror_module模块使用方法详解 (opens new window)
- Nginx流量复制 (opens new window)
# 手机端/PC端共用一个地址
手机端/PC端共用一个地址,手机端自动导航到手机端页面
# 访问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;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 文件服务器
# 文件服务器
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 {
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# nginx端口转发
# 编译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服务了
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# nginx携带cookie
参考文档
有些请求授权从cookie里携带参数,让前端直接发送携带cookie的请求比较难搞,后台还要添加一些跨域配置,通过nginx代理就能轻松做到
- 将原来要传到cookie属性的数据放到cookie2请求头属性
- 通过开启携带cookie配置,以及cookie请求头数据添加成功拼上Cookie
# 携带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/;
}
2
3
4
5
6
7
8
# 端口共用
一般一个应用一个端口,但是nginx可以通过区分
server_name达到端口共用,此类做法适用于有域名的场景 本文示例nginx安装目录为/usr/local/nginx,购买域名为example.com
- 在nginx配置目录下,创建目录
conf.d
mkdir -p /usr/local/nginx/conf/conf.d
- 编辑
/usr/local/nginx/conf/nginx.conf配置文件,在http块添加如下配置
include /usr/local/nginx/conf/conf.d/*.conf;
- 新增
/usr/local/nginx/conf/conf.d/domain1.example.com.conf配置文件作为站点1配置,添加如下配置
注意
server_name要与文件名一致
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;
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# http强制跳转https
参考文档
- nginx将https协议反向代理到http协议请求上的实现 (opens new window)
在
http-server-80块添加
return 301 https://$host$request_uri;
# redis
# 常用配置
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持久化
2
3
4
5
6
7
# mysql
# MongoDB
- mongod.cfg
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
2
3
4
5
6
7
8
9
10
11
12
安装服务
mongod --config "D:\Program\mongodb3.6.23\mongod.cfg" --install
# chfs
chfs.ini (opens new window) | 直chfs.ini | 直chfs.ini