Friday, December 25, 2015

删除 CASLYXThesis 模板目录中的目录

中科院 CASLYXThesis 模板注释非常详细,比较适合我们这些新手使用。但是模板在总目录里面有致谢、目录、插图目录和表格目录,好多以此模板为基础的修改版都没有去掉目录中的目录。在 CTeX 论坛上咨询后得到了解决的办法,现分享出来。

\def\@schapter#1{
  % \addtocontents \addcontentsline
  %     \addtocontents{toc}{\protect\addvspace{6\[email protected]}}
  \addcontentsline{toc}{chapter}{#1}%
  \@makeschapterhead{#1}%
  \@afterheading
}

原模板的下载地址为:http://bit.ly/1Mz5Vk7

via Chu's Space http://bit.ly/1Od50eC

Shadowsocks 安装配置

1.服务端安装
Debian / Ubuntu 系统:

apt-get install python-pip
pip install shadowsocks

2.修改配置文件

/etc/shadowsocks.json

{
    "server":"my_server_ip",
    "server_port":8388,
    "local_address": "127.0.0.1",
    "local_port":1080,
    "password":"mypassword",
    "timeout":300,
    "method":"aes-256-cfb",
    "fast_open": false
}

3.测试配置文件

ssserver -c /etc/shadowsocks.json

如果没有错误提示就可以在后端运行了:

ssserver -c /etc/shadowsocks.json -d start

终止运行:

ssserver -c /etc/shadowsocks.json -d stop

参考资料:http://bit.ly/1PnJK6Z

via Chu's Space http://bit.ly/1OkFxM1

Monday, December 21, 2015

解决树莓派打印机停止打印的问题

前面在《Raspberry Pi搭建打印服务器》一文中记录了在 Raspberry Pi 搭建打印机的全过程,稳定运行了好久,昨天因为断电,导致重启后出现错误:

USB printer stopped working: "/usr/lib/cups/backend/hp failed

解决方法如下:

1.访问 http://bit.ly/1OFfShD

2.Administrator-HPPrinter-Manage Printers-”Resume Printer”,然后出入管理员帐号和密码就可以了。

via Chu's Space http://bit.ly/1OFfQq0

Friday, December 18, 2015

OpenVZ VPS 上使用 IPv6 隧道

1.确认vps支持tun/tap设备
运行

cat /dev/net/tun

如果返回File descriptor in bad state,说明支持tun/tap。否则请发ticket联系客服。

2.注册 IPv6 Tunnel Broker
进入 http://bit.ly/1NX4gKC,点击左上角面板的Register按钮注册一个帐号。
注册完成后登录,点击左侧的 Create Regular Tunnel,在 IPv4 Endpoint (Your side):中填入 VPS 的 IPv4 地址,然后在下面的 Available Tunnel Servers 里选择一个离你 VPS 机房最近的地点。点击 Create Tunnel 创建隧道。

创建完成后进入刚申请的隧道的详情页面,记下以下信息:

Server IPv4 Address: 服务端的 IPv4 地址,假设为 1.2.3.4
Client IPv4 Address: VPS 的 IPv4 地址,假设为 5.6.7.8
Client IPv6 Address: 获得的 IPv6 地址,假设为 2000:200:a:f00::2/64

点击中间的 Example Configurations 选项卡可以看见各种系统上建立隧道的配置方法,不过OpenVZ 虚拟机都是用不了的。此时需要使用用户层的 tb-tun 隧道客户端。

3.编译 tb-tun

wget http://bit.ly/1TTPch4 
tar xvf tb-tun_r18.tar.gz 
gcc tb_userspace.c -l pthread -o tb_userspace 

把编译出的程序移到 $PATH 里:

mv tb_userspace /usr/local/sbin 

用 tb_userspace 创建一个名为 tb 的虚拟接口并后台运行,第一个地址为服务端地址,第二个地址为 VPS 的本地地址:

setsid tb_userspace tb 184.105.253.14 181.215.100.97 sit 

启用虚拟接口:

ifconfig tb up 

为虚拟接口分配前面申请到的 IPv6 地址:

ifconfig tb inet6 add 2001:470:1f10:37e::2/64 

调整虚拟接口的最大传输单元:(这步可以不做)

ifconfig tb mtu 1480 

添加 IPv6 路由:

/sbin/route -A inet6 add ::/0 dev tb 
/sbin/ip -6 route add default dev tb 

参考资料:http://bit.ly/1NX4gKD

via Chu's Space http://bit.ly/1TTPbtj

Google Schloar 配置文件

1.安装编译环境

apt-get install build-essential git gcc g++ make

2.安装 lua

apt-get install liblua5.1-0-dev liblua50-dev liblualib50-dev

3.安装 luajit

wget http://bit.ly/22d7UWI
tar -zxvf LuaJIT-2.0.3.tar.gz
cd LuaJIT-2.0.3
make PREFIX=/usr/local
make install

4.下载 nginx
因为 lua-nginx-module 只支持 Lua 5.1 或者 LuaJIT 2.0/2.1 版本,nginx 目前最高支持 1.9.3版本,所以需要设置 http_spdy_module 模块,1.9.5版本以上就可以支持
http_v2_module 模块了。

wget "http://bit.ly/1k6f90z"
wget "http://bit.ly/1Z0nKlf"
wget "http://bit.ly/1Z0nMta"
wget "http://bit.ly/1QgFmrr"

git clone http://bit.ly/1QgFoPZ
git clone http://bit.ly/1QgFmrs
git clone http://bit.ly/22d7WOo
git clone http://bit.ly/1k6f9gQ

tar xzvf nginx-1.7.8.tar.gz
tar xzvf pcre-8.38.tar.gz
tar xzvf openssl-1.0.1j.tar.gz
tar xzvf zlib-1.2.8.tar.gz

5.编译安装 nginx

./configure \
  --user=root \
  --group=root \
  --prefix=/usr/local/nginx \
  --with-pcre=../pcre-8.38 \
  --with-openssl=../openssl-1.0.1j \
  --with-zlib=../zlib-1.2.8 \
  --with-http_ssl_module \
  --with-http_stub_status_module \
  --with-http_ssl_module \
  --with-http_spdy_module \
  --with-http_gzip_static_module \
  --with-ipv6 \
  --with-http_sub_module \
  --add-module=../ngx_http_google_filter_module \
  --add-module=../ngx_http_substitutions_filter_module \
  --add-module=../ngx_devel_kit \
  --add-module=../lua-nginx-module

参考资料:http://bit.ly/1k6faBF

6.编辑 nginx.conf

#user  nobody;
worker_processes  auto;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;


events {
    use epoll;
    worker_connections 51200;
    multi_accept on;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    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 256k;

    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;
    gzip_proxied        expired no-cache no-store private auth;
    gzip_disable        "MSIE [1-6]\.";

    server {
        listen       80;
        server_name  scholar.xxx.com;
        rewrite ^(.*) http://bit.ly/22d7WOs permanent;
           }

    server {
        listen 443 spdy;
        server_name scholar.xxx.com;

        ssl on;
        ssl_certificate /usr/local/nginx/conf/xxx.crt;
        ssl_certificate_key /usr/local/nginx/conf/xxx.key;
        ssl_dhparam /usr/local/nginx/conf/dhparam2048.pem;
        add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains; preload';
        ssl_prefer_server_ciphers on;
        ssl_ciphers 'kEECDH+ECDSA+AES128 kEECDH+ECDSA+AES256 kEECDH+AES128 kEECDH+AES256 kEDH+AES128 kEDH+AES256 DES-CBC3-SHA +SHA !aNULL !eNULL !LOW !MD5 !EXP !DSS !PSK !SRP !kECDH !CAMELLIA !RC4 !SEED';
        ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
        ssl_session_cache   shared:SSL:10m;
        ssl_session_timeout 10m;
        keepalive_timeout   70;
        ssl_buffer_size 1400;
        spdy_headers_comp 0;

        resolver 8.8.8.8;
        location / {
            set $upstream "";
            rewrite_by_lua '
                 local upstreams = {
                       "http://a.xxx.com",
                       "http://b.xxx.com",
                       "http://c.xxx.com"
                                   }
                 ngx.var.upstream=upstreams[ math.random( #upstreams ) ]
                             ';

            #resolver 8.8.8.8;
            proxy_buffering off;
            proxy_redirect off;
            proxy_set_header Accept-Encoding "";
            proxy_set_header User-Agent $http_user_agent;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass       $upstream;
                    }
             }
    }

7.注意事项
我在一台 VPS 上很容易就安装完成了,但是在另外一台 VPS 就死活是 502 错误,找了好久才知道是 DNS 解析的问题,需要添加 resolver 8.8.8.8; 才能正常使用。

解答问题是在这里找到的:

http://bit.ly/1k6faBH

It seems a bit strange that nginx is failing to resolve the domain name at runtime rather than at configuration time (since the domain name is hard coded). Adding a resolver declaration to the location block usually fixes dns issues experienced at runtime. So your location block might look like:

location ^~ /freegeoip/ {
  #use google as dns
  resolver 8.8.8.8;
  proxy_pass http://bit.ly/22d7WOu;
}

而我将 resolver 8.8.8.8; 提到 location / 前面去了,作用是一样的。到此为止,将 Google 搜索和 Google Scholar 都配置完成了,解决了在学习中查找资料的问题。由于某同学的建议不要在博客上大肆宣传,所以这将部分配置写出,防止遗忘。

via Chu's Space http://bit.ly/22d7WOw

Saturday, December 12, 2015

HTTP Strict Transport Security on OpenShift

Just create an .htaccess file and add the HSTS header app-root/repo/php.

# Force https
RewriteEngine on 
RewriteCond %{HTTP:X-Forwarded-Proto} !https 
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

# Add HSTS header
Header set Strict-Transport-Security "max-age=31536000"

转自:http://bit.ly/1IL5MPu

via Chu's Space http://bit.ly/1UfSpZ4

Thursday, December 10, 2015

Google Scholar 代理服务器的配置

删除Apache2

$ sudo service apache2 stop
$ sudo apt-get purge apache2 apache2-utils apache2.2-bin apache2-common
$ sudo apt-get autoremove
$ whereis apache2
$ sudo rm -rf /etc/apache2

安装nginx

apt-get install build-essential git gcc g++ make
wget "http://bit.ly/1Z0nKld"
wget "http://bit.ly/1Z0nKlf"
wget "http://bit.ly/1Z0nMta"
wget "http://bit.ly/1QgFmrr"
git clone http://bit.ly/1QgFoPZ
git clone http://bit.ly/1QgFmrs
tar xzvf nginx-1.7.8.tar.gz
tar xzvf pcre-8.38.tar.gz
tar xzvf openssl-1.0.1j.tar.gz
tar xzvf zlib-1.2.8.tar.gz

cd nginx-1.7.8

./configure \
  --prefix=/usr/local/nginx \
  --with-pcre=../pcre-8.38 \
  --with-openssl=../openssl-1.0.1j \
  --with-zlib=../zlib-1.2.8 \
  --with-http_ssl_module \
  --with-http_stub_status_module \
  --with-http_ssl_module \
  --with-http_spdy_module \
  --with-http_gzip_static_module \
  --with-ipv6 \
  --with-http_sub_module \
  --add-module=../ngx_http_google_filter_module \
  --add-module=../ngx_http_substitutions_filter_module

make
make install

配置nginx

server {
  server_name scholar.google.com;
  resolver 8.8.8.8;
  location / {
    proxy_pass http://bit.ly/1QgFoQ0;
  }
}

重启nginx:

/usr/local/nginx/sbin/nginx -s reload

报错代码:

nginx: [error] open() “/usr/local/nginx/logs/nginx.pid” failed (2: No such file or directory)

解决方法:
1.重新运行一下:

/usr/local/nginx/sbin/nginx

2.重启nginx:

/usr/local/nginx/sbin/nginx -s reload

3.运行:

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
via Chu's Space http://bit.ly/1Z0nMtd

Powered by Blogger Skins. Theme: TheBuckmaker | Free Wordpress Templates. Presents HD TV Futurama Streaming. Featured on Wedding Dresses.