叶子

闲言碎语

nginx添加服务器端合并压缩

tengine(ali开发的)有个nginx-http-concat插件,可以在服务器端合并压缩css和js,打算装上。

因为之前的nginx是yum install的,缺少必要的编译和安装库。

看nginx安装路径

rpm -ql nginx

我的安装在/usr/sbin/nginx

查看nginx安装参数

/usr/sbin/nginx -V

拷贝参数出来

安装git

yum -y install git

git http-concat库

git clone git://github.com/alibaba/nginx-http-concar.git

放在了/root/nginx-http-concat

看nginx版本

rpm -q nginx

获取对应版本

wget http://nginx.org/download/nginx-1.0.15.tar.gz

解压

tar zxvf nginx.1.0.15.tar.gz

解压到了/root/nginx-1.0.15/

cd /root/nginx-1.0.15
./configure --参数 --add-module=/root/nginx-http-concat

提示gcc未安装

yum install gcc

再来安装nginx,提示pcre未安装

yum -y install pcre-devel

再来安装nginx,提示openssl未安装

yum -y install openssql openssql-devel

再来安装nginx,提示libxml2/libxslt未安装

不装了,直接参数里关闭

make && make install

之后开启nginx

service nginx start

在网站的conf里添加

location / {
        index  index.html index.htm;
        concat on;
        concat_max_files 20;
    }

用http://***.com/??css/1.css,css/2.css 访问成功

需要留意的是,css里的图片路径要提前修改为绝对路径,否则合并后路径会出错的

centos 新手记

新入手centos云主机一台,之前没摸过linux,命令行一个不会,查了不少资料,记在这里。

#登录

ssh -q -l 用户名 -p ip地址

#硬盘

fdisk -l 查看硬盘信息
df -h 看已分区盘
fdisk /dev/盘符号   分区
mkfs.ext3 /dev/盘符号  格式化
mkdir /mydata/ 创建目录
mount /dev/盘符号 /mydata 挂载
echo 'dev/盘符 /mydata ext3 defaults 0 0'>> /etc/fstab 添加分区信息
cat /etc/fstab 查看分区信息

####为了安全,网站目录所属用户、nginx+php 和mysql所属用户必须不一样,需要读写权限的另行添加读写权限。 ####下面会设定nginx+php的子线程用户为nobody,网站目录用户为www,mysql目录用户为mysql。 ####严格限定php运行权限目录,比如缓存目录要禁止访问,上传目录禁止执行。

增加网站用户和用户组www

/usr/sbin/groupadd www
/usr/sbin/useradd -g www www

#网站目录 建立

mkdir -p /mydata/web/site1
mkdir -p /mydata/web/site2

给www用户权限

chmod +w /mydata/web/site1
chmod +w /mydata/web/site2
chown -R www:www /mydata/web/site1
chown -R www:www /mydata/web/site2

#nginx 安装后启动nginx

service nginx start

测试nginx

wget http://127.0.0.1

如果有index.html saved就表示正常

创建nginx日志目录

mkdir -p /mydata/log
chmod +w /mydata/log

修改niginx配置

vim /etc/nginx/nginx.conf
user nginx 改成用户组 user nobody
worker_processes 1; 几核一般写几
error_log /mydata/log/error.log crit; 日志路径
events {
	use epoll;
	woker_connections 1024; 看服务器配置
}
pid        /var/run/nginx.pid;
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /mydata/log/access.log  main; 网站访问日志

    sendfile        on;
    tcp_nopush     on;  可改

    keepalive_timeout  60; 连接超时

    tcp_nodelay on;

    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;

    gzip on; 压缩
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_vary on;


    # Load config files from the /etc/nginx/conf.d directory
    # The default server is in conf.d/default.conf
    include /etc/nginx/conf.d/*.conf;
}

给nginx缓存添加权限

chown -R nobody:nobody /var/lib/nginx

/etc/nginx/conf.d/default.conf 默认配置

/etc/nginx/conf.d/ssl.conf https配置

/etc/nginx/conf.d/virtual.conf 多域名配置

/etc/nginx/conf.d/default.conf 修改默认配置 禁止ip和非捆绑域名

server {
    listen     80 default;
    server_name  _;
    rewrite ^(.*) http://www.yeeh.org permanent
 }

/etc/nginx/conf.d/site1.conf 例子

server {
    listen     80;
    root /mydata/web/site1;
    server_name  site1.com www.site1.com;

    #charset koi8-r;

    access_log  /mydata/log/site1.log  main;

    location / {
        index  index.html index.htm index.php;
    }

    error_page  404              /404.html;
    location = /404.html {
        root   /mydata/web/site1;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /mydata/web/site1;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

#php 安装之后,配置

vim /etc/php-fpm.d/www.conf
user = nobody
group = nobody

php.ini配置,添加扩展

vim /etc/php.ini
extension_dir = "/usr/lib64/php/modules/"
extension=mbstring.so
extension=curl.so
extension=fileinfo.so
extension=json.so
extension=phar.so
extension=zip.so

启动

service php-fpm start

#phpmyadmin phpmyadmin这踩坑几次: ###phpmyadmin目录权限必须是755,否则会报错

Wrong permissions on configuration file, should not be world writable!

更改权限

cd /mydata/site1/
chmod -r 755 phpmyadmin

###需要几个扩展,否则会报错,例如

Call to undefined function mb_detect_encoding

安装php-mbstring和php-mysql,php-mcrypt

yum install php-mbstring
yum install php-mysql
yum install php-mcrypt

修改/etc/php.d/mcrypt.ini

extension=mcrypt.so

###session无权限

给session目录添加权限

chown -R nobody:nobody /var/lib/php/session

之后重启php-fpm和nginx

service php-fpm restart
service nginx restart

#mysql

创建用户组

groupadd mysql
useradd -g mysql mysql

创建mysql目录

mkdir -p /mydata/db
chmod +w /mydata/db
chown -R mysql:mysql /mydata/db/

安装mysql

移动数据库目录

mv /var/lib/mysql  /mydata/db/

改变存放目录

vim /etc/my.cnf

指定了编码集和端口

[mysqld]
default-character-set=utf8
init_connect='SET NAMES utf8'
port=3306
datadir=/mydata/db/mysql
socket=/mydata/db/mysql/mysql.sock
user=mysql
symbolic-links=0

[mysqld_safe]
log-error=/mydata/db/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[client]
port=3306
default-character-set=utf8
socket=/mydata/db/mysql/mysql.sock

上面最后的client里的socket不能少,就是少了这个,结果root上去启动mysql正常,但是一看版本就报连不上/var/lib/mysql/mysql.sock,在这走了不少弯路,结果是1没有指示客户端sock连到哪里,二是没有指定用tcp连

没有修改/etc/init.d/mysql这个文件,这个下面也有指定datadir的目录

启动mysql

/etc/init.d/mysql start
或
service mysqld start

看mysqld

/etc/init.d/mysqld

mysql管理

/usr/bin/mysqladmin version
/usr/bin/mysqladmin status

改密码

/usr/bin/mysqladmin -u root password 'new-password'

进入mysql,管理

mysql -u root -p

mysql查看和管理

show variables like 'character%'; //查看编码
show databases;
use mysql;
show tables;

增加删除库

create database 库名;
drop database 库名;

增加用户和密码

grant 操作 on 数据库.* to 用户名@登录主机 identified by "密码"

删除用户

revoke 操作 on 数据库.* from 用户名@登录主机;

刷新权限

flush privileges;

查看权限

show grants for 用户名@主机;

退出

exit;

备份和恢复

cd /mydata/mysql 
mysqldump -u root -p --opt aaa > back_aaa
mysql -u root -p ccc < back_aaa

添加到默认启动列表

chkconfig --add nginx
chkconfig nginx on
chkconfig --add php-fpm
chkconfig php-fpm on
chkconfig --add mysqld
chkconfig mysqld on

#其他

chkconfig --list 列出开机进程
rpm -ql nginx 查看软件包具体的安装目录
rpm -q nginx 查看版本
ps -ef|grep nginx 查看nginx进程和用户组
cat /etc/my.cnf 查看文件
kill -9 进程号  杀进程
netstat -tnlup 查看端口

主要是改了默认的存放目录,和启动用户名导致的多个连环坑…

密码生成器passid.org

一晃2个多月没写blog了,皆因我家叶子小盆友出生忙的人仰马翻,今天把之前挖的坑填上,带来个新鲜小工具第一版,密码生成器,网址是www.passid.org

初衷:常用网站已有50+,管理密码越来越力不从心,之前我的密码策略见这篇怎么尽可能避免泄漏网上隐私,给网站分组不同组使用不同级别的密码,然后还准备了个密码本记录了级别,直接的后果就是虽然密码减低为约10组,还是记不住,加上每隔半年需要换,这个过程非常痛苦,不要和我说有1password这样的工具,那个老贵了=_=。那么有没有根据用户名和网站就生成不同密码的呢? 找了一圈没发现,于是有了是www.passid.org

填写用户名,选择在哪个网站使用,就生成好了密码。 对于要求高的用户,还可以自定义salt,选择密码级别,每个网站的密码都不一样,有效防止csdn这样的脱裤,呃是拖库。

faq:

1、架设在github,所有密码在浏览器生成,不提交任何数据到后端,欢迎右键

2、完全开源,代码托管在github,欢迎fork

3、算法采用公开算法的sha512和增加了字符的base64,生成方法为base64(sha512(用户名+网站域名+salt)),有效防止cmd5等网站的现有库^_^

4、base64增加的字符为-@#~,.!%^*$&

ps:不支持低于ie9下的浏览器,如果侥幸浏览正常,实属意外。实际上我只测试过mac上的chrome,因为只忙了几小时…

ps2:第一版代码也比较丑…