2020年7月
nginx 记录 客户端IP和CDN IP
http {} 中:
map $http_x_forwarded_for $clientRealIp {
"" $remote_addr;
~^(?P<firstAddr>[0-9\.]+),?.*$ $firstAddr;
}
log_format main 'src:$clientRealIp cdn:$remote_addr $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent"';
access_log logs/access.log main;
samba 集成DEV开发环境 php 监控某目录下文件变动,自动执行某些命令操作 重启nginx ,nginx 实现动态域名,动态配置加载
测试环境:
centos 7系统,预先安装好bt 宝塔系统,安装好samba,宝塔里面安装好 lnmp软件,php设置 取消 exec 函数限制:
将www用户添加到dev组
usermod -G dev www
php 写了一个脚本,实现监控目录下文件的变量,然后重启nginx的例子:
<?php
class NginxRewrite {
public $dir = "/www/wwwroot/";
private $files = [];
public function __construct() {
$this->files = $this->readDir();
}
public function run() {
$oldFiles = $this->files;
while (true) {
$_files = $this->readDir();
foreach ($_files as $f=>$t) {
if (!isset($oldFiles[$f]) || $oldFiles[$f]!=$t) {
$oldFiles = $_files;
@exec("nginx -t", $out, $status);
if ($status === 0) {
echo "rewrite change, nginx reload\n";
@exec("nginx -s reload");
}
break;
}
}
sleep(10);
}
}
//目录目标目录
private function readDir($dir = null) {
$dir = $dir ? $dir : $this->dir;
$files = scandir($dir);
$deep = count(explode(DIRECTORY_SEPARATOR, $this->dir));
//var_dump($deep);
$res = [];
foreach ($files as $file) {
if ($file == '..' || $file == '.')
continue;
$_path = rtrim($dir, '\\/') . DIRECTORY_SEPARATOR . $file;
$_deep = count(explode(DIRECTORY_SEPARATOR, $_path));
if (is_dir($_path) && $_deep - $deep < 2) {
//var_dump($_deep - $deep, $_path);
$res = array_merge($res, $this->readDir($_path));
} elseif (is_file($_path) && preg_match("/nginx\.htaccess$/", $file)) {
$res[$_path] = filemtime($_path);
}
}
return $res;
}
}
$mod = new NginxRewrite();
$mod->run();
nginx 实现了动态域名,动态加载用户的匹配文件的方法
/root/nginx_config_tpl/www.nginx.tpl
server
{
listen 80;
server_name ~^(\w+)\.USER_NAME\.tell520\.com$;
set $www $1;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/USER_NAME/$www;
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
#SSL-END
#ERROR-PAGE-START 错误页配置,可以注释、删除或修改
#error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-START PHP引用配置,可以注释或修改
include enable-php-71.conf;
#PHP-INFO-END
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
location / {
include /www/wwwroot/USER_NAME/*/nginx.htaccess;
access_log /www/wwwroot/USER_NAME/nginx.log;
}
#REWRITE-END
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
allow all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log off;
access_log /dev/null;
}
location ~ .*\.(js|css)?$
{
expires 12h;
error_log off;
access_log /dev/null;
}
}
自动创建samba用户,并创建用户的网站目录和默认的例子文件脚本:
#! /bin/bash
if [ $# -ne 1 ]; then
echo -e "use: ./create_dev_user.sh username"
exit 1
fi
useradd $1 -g dev
echo -e "123456\n123456\n" | smbpasswd -a $1
mkdir /www/wwwroot/$1
mkdir /www/wwwroot/$1/test
touch /www/wwwroot/$1/test/index.php
cat>/www/wwwroot/$1/test/index.php<<EOF
<?php
echo "<pre>";
echo "hello world!\n";
var_export(\$_GET);
echo "</pre>";
EOF
touch /www/wwwroot/$1/test/nginx.htaccess
cat>/www/wwwroot/$1/test/nginx.htaccess<<EOF
rewrite ^([^\.]*)/(\w+)/(\w+).html\$ \$1/index.php?r=\$2/\$3 last;
rewrite ^([^\.]*)$ \$1/index.php?r=index/index last;
if (!-e \$request_filename) {
rewrite ^(.*)\$ /index.php/\$1 last;
}
EOF
chown $1:dev /www/wwwroot/$1/ -R
chmod 776 /www/wwwroot/$1/ -R
sed "s/USER_NAME/$1/" /root/nginx_config_tpl/www.nginx.tpl > /www/server/nginx/conf/vhost/$1.conf
echo -e "\033[34mAdd hosts to browse the example site : 192.168.2.164 test.$1.tell520.com\033[0m"
echo -e "\033[34mAdd network drive : \\\\192.168.2.164\dev\033[0m"
echo -e "\033[34mUser AND Password : $1, 123456\033[0m"
nginx -t && nginx -s reload
samba配置文件:
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.
[global]
server string = dev Servera Version %v
interfaces = ens192 192.168.2.164/24
workgroup = SAMBA
security = user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[dev]
comment = dev dir
path = /www/wwwroot/yxb
browseable = Yes
writable = Yes
available = Yes
valid users = @dev
public = No
[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = Yes
read only = No
inherit acls = Yes
[printers]
comment = All Printers
path = /var/tmp
printable = Yes
create mask = 0600
browseable = No
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = @printadmin root
force group = @printadmin
create mask = 0664
directory mask = 0775
python 打包成exe执行文件
1. 在命令行用pip安装 pyinstaller包
pip install pyinstaller
2.下载安装pyinstaler运行时所需要的windows扩展pywin32
mhammond/pywin32
下载地址:https://github.com/mhammond/pywin32/releases
选择最新版的下载,注意要选择对应的python版本(version)和python位数(bittedness)
通过在命令行输入python查看python版本和位数
如下所示为python3.6的32位,需要下载[pywin32-223.win32-py3.6.exe]
Python 3.6.3 ... [MSC v.1900 32 bit (Intel)] on win32
如下所示为python3.6的64位,需要下载[pywin32-223.win-amd64-py3.6.exe]
Python 3.6.3 ... [MSC v.1900 64 bit (AMD64)] on win32
3.在命令行中直接输入下面的指令即可
pyinstaller [opts] yourprogram.py
参数含义
-F 指定打包后只生成一个exe格式的文件(建议写上这个参数)
-D –onedir 创建一个目录,包含exe文件,但会依赖很多文件(默认选项)
-c –console, –nowindowed 使用控制台,无界面(默认)
-w –windowed, –noconsole 使用窗口,无控制台
-p 添加搜索路径,让其找到对应的库。
-i 改变生成程序的icon图标(比如给女朋友写的程序,换个好看的图标,默认的很丑)
例子:
print('hello world')
name = input("Tell me your name,and I will repeat it back to you:")
print('thank\'s ' + name)
input("will exit:")
保存为first.py
执行:
pyinstaller.exe -F .\first.py
phpstorm自动处理CSS单位格式化后出现多余空格的问题
借助sed命令,实时监控文件,替换空格
https://github.com/mbuilov/sed-windows
-i s/"\ upx"/upx/g $FilePath$
$FilePath$
Mac系统配置如下