cd /www/server/panel/install/
echo “sed -i -e ’49s/nginx/yourwebserver/’ /www/server/nginx/src/src/http/ngx_http_header_filter_module.c” > /www/server/panel/install/nginx_prepare.sh
sh nginx.sh install 1.16
分类目录归档:LINUX运维总结
利用ssh隧道端口转发,方便调试内网服务器
目标把内网A主机(IP地址: a.a.a.a) 的80端口,通过外网主机(IP地址: b.b.b.b)端口 8080暴露到公网。
A,B都为CentOS Linux. 并且B不能ssh到A
下面从A测试 ssh -NTR 0.0.0.0:8080:0.0.0.0:80 [email protected] -p 22
(请先设置B可以让A 采用key方式免密登录。自行Google)
然后在B上面看 netstat -anlp | grep ssh | grep 8080 ,可以看到相应的
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 1800/sshd: root
tcp6 0 0 :::8080 :::* LISTEN 1800/sshd: root
在B,需要改写 /etc/ssh/sshd_config 里面 GatewayPorts yes,然后B 重启ssh , systemctl restart sshd
测试端口是否已经转发 curl -v http://b.b.b.b:8080
关于让A可以自动在断线后连接B,可以做如下处理
A修改 /etc/ssh/ssh_config 增加
ServerAliveInterval 10
ServerAliveCountMax 3
B修改 /etc/ssh/sshd_config,增加
ClientAliveInterval 10
ClientAliveCountMax 3
同时A做一个service
vi /usr/lib/systemd/system/ssh-link.service
[Unit]
Description=ssh port forwarding service.
[Service]
Type=simple
ExecStart= /bin/sh -c 'ssh -NT -R 8080:0.0.0.0:80 [email protected] -p 22'
Restart=always
RestartSec=10
User=root
Group=root
[Install]
WantedBy=multi-user.target
启动
systemctl start ssh-link
加入自动启动
systemctl enable ssh-link
本文参考 :https://segmentfault.com/a/1190000038153088
备注,关于如果B不改写 GatewayPorts yes, 在B上面只能有 127.0.0.1:8080的绑定,不过可以通过nginx的proxy来实现对127.0.0.1:8080的代理,配置代码如下:
stream {
server {
listen 8081;
proxy_pass 127.0.0.1:8080;
}
}
wd blue ssd 西数固态盘 绿盘数据修复
下面是硬盘的 smartctl -i /dev/sdd 的信息,
Model Family: WD Blue and Green SSDs
Device Model: WDC WDS100T2G0A-00JH30
Serial Number: 19099D802020
LU WWN Device Id: 5 001b44 8b8446785
Firmware Version: UH510000
User Capacity: 1,000,207,286,272 bytes [1.00 TB]
Sector Size: 512 bytes logical/physical
Rotation Rate: Solid State Device
Form Factor: 2.5 inches
Device is: In smartctl database [for details use: -P show]
ATA Version is: ACS-2 T13/2015-D revision 3
SATA Version is: SATA 3.2, 6.0 Gb/s (current: 3.0 Gb/s)
Local Time is: Fri Feb 19 21:40:34 2021 CST
SMART support is: Available – device has SMART capability.
SMART support is: Enabled
这个固态盘的数据是用lvm管理的,数据格式是 xfs ,但是 在 mount的时候提示 bad superblock , 采用 xfs_repaire 无法直接在原硬盘修复。
用 dd if=/dev/volume-group/lvname of=/big_good_dir/lvname.img
然后 xfs_repair /big_good_dir/lvname.img 修复,或者
xfs_repair -L /big_good_dir/lvname.img
最后 mount -o loop -t xfs /big_good_dir/lvname.img /mnt 在 /mnt 里面查看文件。至此结束修复。
docker跑tinydns
docker pull jbanetwork/tinydns
假设在/etc/tinydnsdocker/目录下存在data文件是解析文件
docker run -it –rm -v /etc/tinydnsdocker:/opt/tinydns jbanetwork/tinydns:latest tinydns-data
docker stop tinydns
docker rm tinydns
docker run -d –read-only -p 53:53/udp –name tinydns –restart=always -v /etc/tinydnsdocker:/opt/tinydns jbanetwork/tinydns:latest
mysql开启慢日志
log-slow-queries = /tmp/mysql-slow.log
long_query_time = 2
apache rewrite 转 iis web.config
apache rewrite 转 iis web.config
1) ^(.*)/ 替换为 ^ ,
2) $1/ 删除
3) . ? 去掉前面的 \
4) $N 更换为 $N-1 ,从大到小换!!!
例子
RewriteRule ^(.*)/read_([0-9]+)/([0-9]+).html$ $1/modules/article/reader.php\?aid=$2&cid=$3
需要改为
RewriteRule ^read_([0-9]+)/([0-9]+).html$ modules/article/reader.php?aid=$1&cid=$2
web.config 就可以是
借用工具
Cannot load M3U8: crossdomain access denied
有时候仅仅是因为你的m3u8源采用了https 并且 禁止了http的调用,那么只需要把自己配置好https即可,有关nginx的配置https,简单!
pure-ftp 服务器发回了不可路由的地址,使用服务器地址代替
一些服务器供应商的服务器采用反向nat方式,只给服务器内网ip,外网ip是映射得到的,比如172.x.x.x 或者 192.168.x.x , pure-ftp会返回这些内部ip的地址,从而导致外部互联网用户不可能达到。
到阿里云或者别的什么云,把防火墙里面的 39000-40000端口放开
curl 测试https指定Host头
curl -v -k -I -H “Host:www.domain_name.com” https://ip:port/url
参数解释:
curl –help
-v: verbose 详细信息
-k: 不验证证书
-I:只显示头信息
-H:发送的Header
apache 的代理 proxypass 正则匹配
ProxyPass /la http://后端地址
ProxyPassMatch ^/la.* http://后端地址
ProxyPassReverse /la http://后端地址
匹配地址
nginx配置文件的编码问题
nginx的配置文件居然可以用多种编码,比如utf8和gbk两种,
需要你把utf8和gbk分别写入两个文件比如 vhost1.conf vhost2.conf
然后在 nginx.conf 里面 include vhost1.conf; include vhost2.conf; 即可
这类应用一般是你在需要些配置文件时候用到中文的时候。
比如 :
subs_filter ‘nihao’ ‘你好’;
有关,nginx的 subs_filter 是定制模块 地址在 https://github.com/yaoweibin/ngx_http_substitutions_filter_module
lftp 设置主被动模式
set ftp:passive-mode on
iptables 根据ip设置开放某些ip的访问,ip地址段 a-b 的方式
IPB=/sbin/iptables $IPB -F INPUT for kk in ` cat ip.txt | awk '{printf ("%s_%s\n",$1,$2)}'` do #echo $kk startip=`echo $kk | awk -F "_" '{print $1}'` endip=`echo $kk | awk -F "_" '{print $2}'` $IPB -A INPUT -p tcp --dport 80 -m iprange --src-range $startip-$endip -j ACCEPT done ### deny all $IPB -A INPUT -p tcp --dport 80 -j DROP
ip.txt内容是
1.0.1.0 1.0.3.255 768
1.0.8.0 1.0.15.255 2,048
1.0.32.0 1.0.63.255 8,192
nginx 设置首次访问跳转,通过cookie设置
location / {
if ($cookie_firstvisit != “1”) {
return 301 /login.html;
}
}
location = /login.html {
add_header Set-Cookie “firstvisit=1;Max-Age=1000”;
}
postgresql 9.4 和php的编译安装过程
centos 6.X 安装过程
yum install https://download.postgresql.org/pub/repos/yum/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-2.noarch.rpm
yum install postgresql94
yum install postgresql94-server
yum install postgresql94-devel
ln -sf /usr/pgsql-9.4/bin/pg_config /usr/bin/
编译php时候加参数 –with-pgsql –with-pdo-pgsql
thinkphp的nginx配置pathinfo模式,适用3.2 5.0
tp-nginx-config
server
{
# 适用于 thinkphp 3.2 thinkphp 5.0
# pathinfo 模式
# 模块/控制器/方法/参数
# 3.2 使用方法 /home/index/index/params
# 5.0 使用方法 /index/index/index/params
listen 80;
server_name tp;#mod this line
index index.php index.html;
root /tpdir; #mod this line
location / {
index index.php index.htm;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000; #mod this line
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
if ($fastcgi_script_name ~ “^(.+?\.php)(/.+)$”) {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param PATH_INFO $path_info;
}
}
curl和wget的下载,发送域名的命令
wget -c –header “Host:www.domain.com” http://ip.ip.ip.ip/filesname.zip
curl -H “Host:www.domain.com” -o filesname.zip http://ip.ip.ip.ip/filesname.zip
openssl 测试 ssl可用性
nginx 指令和变量集
Alphabetical index of directives
http://nginx.org/en/docs/dirindex.html
Alphabetical index of variables
http://nginx.org/en/docs/varindex.html
nginx的防盗链测试的一点备注
curl -v -e “http://www.not-allow-domain.com” http://yourdomain.com/aaa.jpg
测试的时候必须输入http:// 这样的完整url才好
cr.yp.to 的ucspi daemoontools djbdns 安装
centos 6.X x86_64 安装 rpm 的mysql 5.6 下载如下包
http://repo.mysql.com/yum/mysql-5.6-community/el/6/x86_64/mysql-community-server-5.6.33-2.el6.x86_64.rpm
http://repo.mysql.com/yum/mysql-5.6-community/el/6/x86_64/mysql-community-client-5.6.33-2.el6.x86_64.rpm
http://repo.mysql.com/yum/mysql-5.6-community/el/6/x86_64/mysql-community-common-5.6.33-2.el6.x86_64.rpm
http://repo.mysql.com/yum/mysql-5.6-community/el/6/x86_64/mysql-community-devel-5.6.33-2.el6.x86_64.rpm
http://repo.mysql.com/yum/mysql-5.6-community/el/6/x86_64/mysql-community-libs-5.6.33-2.el6.x86_64.rpm
http://repo.mysql.com/yum/mysql-5.6-community/el/6/x86_64/mysql-community-libs-compat-5.6.33-2.el6.x86_64.rpm
discuz的QQ登录缓慢但是可以登陆,首先检查dns resolver
linux 检查 /etc/resolve.cof
win 查下网卡配置里面的dns
测试方式就是在服务器 打开 http://openapi.qzone.qq.com/oauth/qzoneoauth_request_token
看看速度,如果缓慢基本可以判定就是这个因素
mysql 的 information_schema 库
https://dev.mysql.com/doc/refman/5.7/en/information-schema.html
利用 information_schema 可以做很多事,这个库存储了mysql的元数据!
比如:
1)查询存在哪些 表是 innodb 的
2)查询 innodb 表的大小
3)查询某字段的定义
例子
SELECT table_schema,table_name, table_rows,
ROUND((data_length+index_length)/1024/1024) AS total_mb,
ROUND(data_length/1024/1024) AS data_mb,
ROUND(index_length/1024/1024) AS index_mb
FROM INFORMATION_SCHEMA.TABLES WHERE engine=’InnoDB’
ORDER BY total_mb desc;
nginx 的ssl ,单ip多名ssl,以及方便脚本
首先,nginx 单ip多域名的ssl配置,参考地址是
https://www.zjpro.com/single-ip-mass-https.html
另外,利用 脚本可以比较方便的使用 lets-encrypt 提供的免费ssl,
https://github.com/xdtianyu/scripts/tree/master/lets-encrypt
一个配置文件的例子 letsencrypt.conf-myssl
ACCOUNT_KEY=”letsencrypt-account.key”
DOMAIN_KEY=”/www/ssl/myssldomain.com.key”
DOMAIN_DIR=” /www/myssldomain”
DOMAINS=”DNS:myssldomain.com,DNS:www.myssldomain.com”
方法就是配置 conf文件,然后运行就好了,
letsencrypt.sh letsencrypt.conf-myssl
上面脚本就能自动帮你做注册和生成key的动作。后面只需要修改nginx的配置文件即可
nginx的配置文件,这样写
server
{
listen 80;
listen 443;
if ($scheme = http) {return 301 https://$server_name$request_uri;}
server_name www.myssldomain.com myssldomain.com;
root /www/myssldomain/;
index index.php index.html;
include php.conf;
ssl on;
ssl_certificate “/www/ssl/myssldomain.chained.crt”;
### 注意这里,最好用chained.crt 容易被多数浏览器支持
ssl_certificate_key “/www/ssl/myssldomain.com.key”;
}
wdcp的apache编译ssl模块
下载apache的源文件 http://archive.apache.org/dist/httpd/
解压后进入 modules/ssl 运行下面语句
/www/wdlinux/apache/bin/apxs -a -i -DHAVE_OPENSSL=1 -I/usr/include/openssl -L/usr/lib64/openssl -c *.c -lcrypto -lssl -ldl
下面的3行不一定对。一般来说编辑 conf/extra/httpd-ssl.conf 里面启用 https比较好
下面3行仅供参考:
SSLCertficateChainFile /www/wdlinux/apache/conf/1_root_bundle.crt
SSLCertificateFile /www/wdlinux/apache/conf/2_www.域名.com.crt
SSLCertificateKeyFile /www/wdlinux/apache/conf/3_www.域名.com.key
PS:
http 80 转向到 https 443
.htaccess里面
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://www.yourname.com%{REQUEST_URI} [L,R=301]
</IfModule>
通过http同步时间,当ntpdate 失效时
当ntpdate 失效的时候,还有google
date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z" 国内用百度 date -s "$(wget -qSO- --max-redirect=0 baidu.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
apache 2.4的Substitute模块使用注意
apache 2.4 的 Substitute 模块是个好东西,可以用来实时修改页面内容,做些替换什么的工作,比如
ProxyPass / http://other_web_site.com
ProxyPassReverse / http://other_web_site.com
AddOutputFilterByType SUBSTITUTE text/html
Substitute “s|http://other_web_site.com|http://localhost|i”
可以把网页里面的 http://other_web_site.com 字样替换为 http://localhost
那么有时候 你会发现这个没生效,没法替换,但是这也没什么错误啊,
其实问题很可能是因为你proxy的那个站点用来压缩,导致在Substitute看起来页面是压缩的内容,他当然替换不了,那么必须在压缩前进行解压缩,其实并不需要解压,只需要告诉对方的服务器,我这里不接受压缩的文件,那么就需要另外一个模块了
LoadModule headers_module modules/mod_headers.so
这个模块可以更改proxy模块发到对方的header
RequestHeader set Accept-Encoding “”
那么完整就可以可以这样写
ProxyPass / http://other_web_site.com ProxyPassReverse / http://other_web_site.com RequestHeader set Accept-Encoding "" AddOutputFilterByType SUBSTITUTE text/html Substitute "s|http://other_web_site.com|http://localhost|i"
一共需要启用如下模块
LoadModule filter_module modules/mod_filter.so
LoadModule headers_module modules/mod_headers.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule substitute_module modules/mod_substitute.so
附:有关nginx里面proxy的时候碰到gzip
看这里 http://www.zjpro.com/nginx-substitutions4nginx.html
Linux配置了vpn的ppp,访问百度速度慢或者无法访问
RT,搭设了 VPN,可以访问谷歌 FB等,现在却无法访问百度以及亚马逊,这真的很奇怪,有朋友也遇到相同的问题吗?着急求解!!
|
下载 ip-up-local,上传到服务器的 /etc/ppp/ip-up.local 文件,然后重启ppp服务
service pptpd stop && service pptpd start
参考资料来自
nginx配置防盗链的方法
nginx里面,防盗链需要针对你的域名和泛域名做相应的开放,所有图中 *.domain.com 是必须的,否则你的类似 www.domain.com 也会在屏蔽之列了
location ~* \.(gif|jpg|jpeg|png|bmp|swf|flv)$
{
valid_referers none blocked domain.com *.domain.com baidu.com *.baidu.com ;
if ($invalid_referer) {
return 403;
}
}