2018年1月

在nginx里用 http_referer 阻止指定站点的 Referer 请求访问

有网友提问,想在 nginx 阻止指点站点的 referer 来路访问。

环境:CentOS 7,nginx 1.12

过程:

  1. 如想来自 www.baidu.com 和 www.360.cn 的 referer 返回403错误
  2. 在 server 站点配置内容中,在 location 的命令位置上添加以下内容:

    location / {
             valid_referers www.baidu.com www.360.cn;
             if ($invalid_referer = ''){
                     return 403;
             }
     }
  3. 重启nginx后测试,能收到效果

参考:

在 Ubuntu 16 里安装SMRT Analysis 2.3

感谢张天给机会安装。

SMRT Analysis 软件能帮助科研人员对基因测序。单安装包集成tomcat, mysql等,自动安装,挺方便。

环境:Ubuntu 16.04 64位(或许Ubuntu 14更合适些), SMRT Analysis 2.3,计划安装在 /home/smrtanalysis,单机安装,无job manager system。

过程:

  1. sudo adduser smrtanalysis # 添加 smrtanalysis 用户和组
  2. 将安装文件,smrtanalysis_2.3.0.140936.run 和 smrtanalysis-patch_2.3.0.140936.p5.run 上传到 /home/smrtanalysis 目录
  3. su smrtanalysis # 切换到 smrtanalysis 用户
  4. bash smrtanalysis_2.3.0.140936.run -p smrtanalysis-patch_2.3.0.140936.p5.run --rootdir /home/smrtanalysis/ # 开始安装
  5. 问,是否使用 smrtanalysis 运行,保持默认
  6. 环境检测,图中提示ubuntu版本不支持,可能过新(16.04);提示至少需要8个CPU, 本例测试机仅有1个CPU
  7. 问,用什么网址来访问测序程序入口,本例是用swas.anqun.org,默认是用系统中的IP地址
  8. 问,tomcat用哪些端口,本例保持默认的8080
  9. 问,临时目录和数据目录设置在哪里,本例保持默认
  10. 问,mysql使用什么端口,本例保持默认 53306
  11. 问,是否有 job management system,本例选择没有,NONE
  12. 之后就会根据回答,生成配置文件
  13. 安装成功
  14. /home/smrtanalysis/admin/bin/smrtportald-initd start # 启动 tomcat 和 mysql
  15. /home/smrtanalysis/admin/bin/kodosd start # 启动 kodosd
  16. 如果顺利,可以在进程中查询到 tomcat, mysql 和 kodosd 的进程信息
  17. 在 Chrome 浏览器里输入网址,本例是: swas.anqun.org:8080/smrtportal 就可以看到页面内容了
  18. 首次可以点击右上角的 Register 链接,注册默认的 administrator 用户
  19. 注册用户时,要求密码至少八位,且须包含一个特殊字符,如#

参考:

在Debian 8 系统里为 postfix 配置外部smtp服务器发邮件

有不少网友在使用阿里云ECS实例时,发现无法发出邮件,因为新近创建的ECS实例默认禁止连接外网TCP 25端口,避免滥发邮件。

环境:Debian 8,postfix 2.11,使用免费的阿里云云邮账户发信

过程:

  1. apt-get update # 先更新软件库
  2. hostname swas.anqun.org # 设置主机名
  3. apt-get install libsasl2-modules postfix # 安装 postfix 及相关组件
  4. 在配置 postfix 里,选择 Internet Site 类型,填写完整主机名 swas.anqun.org
  5. 安装好 postfix 后,在配置文件 /etc/postfix/main.cf 里确认 myhostname 的值是否与主机名相符
  6. apt-get install stunnel # 安装stunnel,目的是让postfix支持连接 smtp.aliyun.com:465
  7. 创建 /etc/stunnel/stunnel.conf 配置文件,内容如下,监听本地11125端口,连接 smtp.aliyun.com:465

    [smtp-tls-wrapper]
    accept = 11125
    client = yes
    connect = smtp.aliyun.com:465
  8. 启动 stunnel 后,可查看到本地有 11125 端口使用情况
  9. 创建或修改 /etc/postfix/sasl/sasl_passwd 文件,写上相应的服务器地址、端口和登录名密码,如下例:

    [localhost]:11125 anqunhe@aliyun.com:password
  10. postmap /etc/postfix/sasl/sasl_passwd # 生成 hash 文件
  11. chmod 600 /etc/postfix/sasl/* # 为了保护smtp的登录信息,需要修改上边两个文件为root用户只读写
  12. 修改 /etc/postfix/main.cf 文件,修改 relayhost = [localhost]:11125 , 添加SMTP验证信息:

    # See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
    # information on enabling SSL in the smtp client.
    
    smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
    myhostname = swas.anqun.org
    alias_maps = hash:/etc/aliases
    alias_database = hash:/etc/aliases
    myorigin = /etc/mailname
    mydestination = swas.anqun.org, localhost, localhost.localdomain, localhost
    # relayhost =
    relayhost = [localhost]:11125
    mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
    mailbox_command = procmail -a "$EXTENSION"
    mailbox_size_limit = 0
    recipient_delimiter = +
    inet_interfaces = all
    
    #### SMTP
    # Enable SASL authentication
    smtp_sasl_auth_enable = yes
    # Disallow methods that allow anonymous authentication
    smtp_sasl_security_options = noanonymous
    # Location of sasl_passwd
    smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
    # Enable STARTTLS encryption
    # smtp_tls_security_level = encrypt
    # Location of CA certificates
    smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
    
    smtp_generic_maps = hash:/etc/postfix/generic
    
  13. 因为多数免费邮箱限定发信人是登录名(如anqunhe@aliyun.com),所以在 /etc/postfix/generic 文件里填写可能发信的地址,如:www-data,wordpress

    www-data anqunhe@aliyun.com
    wordpress anqunhe@aliyun.com
  14. postmap /etc/postfix/generic # 生成或更新postfix查询表
  15. service postfix restart # 重启postfix后,从Shell和从wordpress程序测试,发信成功

参考:

在Debian 8里安装foxphp3.0.1

看到云友在安装foxphp遇到了小问题,所以实践一下。

环境:debian 8,nginx 1.6, php 5.6,foxphp3.0.1

过程:

  1. 先安装好php+mysql的环境,请参考这里:https://bbs.aliyun.com/read/288162.html
  2. apt-get install php5-curl php5-gd # 因foxphp要求curl和gd组件,所以补安装
  3. chown -R www-data:www-data /var/www/html # 将foxmphp文件所在的目录修改为web进程用户(www-data)所有
  4. 修改站点配置文件 /etc/nginx/sites-enabled/default ,修改静态化规则内容:

         location / {
                 # First attempt to serve request as file, then
                 # as directory, then fall back to displaying a 404.
                 # try_files $uri $uri/ =404;
                    if (!-e $request_filename) {
                    rewrite  ^(.*)$  /index.php?s=$1  last;
                    break;
                     }
         }
  5. 通过浏览器访问站点,开始安装foxphp,可顺利完成,网站前后台显示内容正常

参考:http://doc.thinkphp.cn/manual/hidden_index.html