Code Monkey home page Code Monkey logo

ioteco's People

Contributors

downgoon avatar

ioteco's Issues

nginx prefix problem

nginx 源代码编译时,指定 --prefix,编译后整个目录移动到其他目录,则无法工作,必须是相同目录。

nginx_upload_module md5.h not found

问题描述:

编译 nginx_upload_module-2.2.0.tar.gznginx-1.2.7.tar.gz 时,会出现:

ngx_http_upload_module.c:14:10: fatal error: 'md5.h' file not found

分析问题

查看代码 ngx_http_upload_module.c 第14行:

#if (NGX_HAVE_OPENSSL_MD5_H)
#include <openssl/md5.h>
#else
#include <md5.h>
#endif

如果 Nignx里面有 openssl 的md5.h,那就引用openssl里面的;否则,直接引用 md5.h。
只要让直接引用 openssl/md5.h ,问题就解决了。而 openssl/md5.h 要存在,就必须安装 openssl 的开发版(devel),而不是使用版。

解决问题

  • ubuntu
apt-get install openssl libssl-dev  # libssl-dev 就是 openssl 的开发版
apt-get install libpcre3 libpcre3-dev
apt-get install zlib1g-dev

ignore a particular error in bash shell script

bash 通常执行到某条语句如果出现错误,则会终止后面语句的运行。但是有时候,我们对一些无关紧要的错误,可以跳过,改怎么办?

实验

  • case A
#!/bin/bash
set -e
echo "before error"
cat /no/path/to/file   # statement-1
echo "after error"

输出:

before error
  • case B
#!/bin/bash
set -e
echo "before error"
cat /no/path/to/file  || true  # statement-2
echo "after error"

输出:

before error
after error

结论

在语句后面加|| true,例如: cat /no/path/to/file || true

解释

Every script you write should include set -e at the top. This tells bash that it should exit the script if any statement returns a non-true return value. The benefit of using -e is that it prevents errors snowballing into serious issues when they could have been caught earlier. Again, for readability you may want to use set -o errexit.

command  
if [ "$?"-ne 0]; then   
    echo "command failed";   
    exit 1;   
fi   

等效:

command || { echo "command failed"; exit 1; }  

What if you have a command that returns non-zero or you are not interested in its return value? You can use command || true, or if you have a longer section of code, you can turn off the error checking, but I recommend you use this sparingly.

sed tips on mac

Mac下替换文本中的内容

Mac的Sed和Linux中的稍有不同,如果需要替换文本内容,需要加 -i 的参数。但是加上 -i 后就必须指定备份文件的后缀名,也就是说,执行替换的时候,会自动备份原文件。

sed -i.backup "s/xx/yy/g" abc.txt

其中 .backup 就是替换前的备份文件。


如果我们不想要备份怎么办,可以用下面的方法:

sed -i '' "s/xx/yy/g" abc.txt

也可以这么写

sed -ig "s/xx/yy/g" abc.txt

ngx_http_upload_module variable ‘result’ set but not used

ngx_http_upload_module.c:1681:18:error: variable ‘result’ set but not used [-Werror=unused-but-set-variable]

解决办法

vi objs/Makefile
CFLAGS = -pipe  -O -W -Wall -Wpointer-arith-Wno-unused-parameter -Werror –g
CFLAGS = -pipe  -O -W -Wall -Wpointer-arith-Wno-unused-parameter -g  

编辑 objs/Makefile 文件,把其中的

CFLAGS = -pipe  -O -W -Wall -Wpointer-arith-Wno-unused-parameter -Werror –g

替换成

CFLAGS = -pipe  -O -W -Wall -Wpointer-arith-Wno-unused-parameter -g  

参考资料

remove prefix when nginx proxy_pass

语句A和语句B的区别 ?

语句A:

location /dbapi/ {
	proxy_pass http://databaseupstream;
}

语句B:

location /dbapi/ {
	proxy_pass http://databaseupstream/;
}

语句C:

location /dbapi/ {
	rewrite /dbapi/(.*)$ /$1 break;
    proxy_pass http://databaseupstream;
}

区别:

  • 在语句A中,访问 /dbapi/employee.json,转发时依然是 /dbapi/employee.json
  • 在语句B中,访问/dbapi/employee.json,转发时,前缀会被切掉,变成 /employee.json
  • 在语句C中,完全等价于语句B。只是实现方式用的是URL重写。

参考资料:

trim whitespace from a bash variable

在bash里面trim一个字符串两头的空白,只要用 echo 输出就可以。

foo="    qsdqsd qsdqs q qs     "

# Not trimmed
echo -e \'$foo\'

# Trim
foo=`echo $foo`

# Trimmed
echo -e \'$foo\'

http_proxy setting tips

设置 http_proxy 的时候:

export http_proxy=http://10.199.75.12:8080
export https_proxy=$http_proxy

如果本地nginx向后端转发时,需要转发后端时,必须设置 no_proxy

export no_proxy="localhost,127.0.0.1,*.local,10.0.0.0/8,192.168.0.0/16,172.16.0.0/12,10.213.42.230"

注意

no_proxy的统配,各平台支持力度不一样。有的能支持 10.0.0.0/8 表示所有以10.X.X.X的内网地址,有的则不可以,比如ubuntu上不支持。必须写10.213.42.230这种的。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.