Nginx settings
1 | user www-data; |
包含文件的例子
- rails.conf
1 |
所有的动态页面交给tomcat 等处理
1 |
|
所有静态文件由nginx直接读取
1 | location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt |
nginx 中upstream轮询机制
轮询 后端服务器down掉,可以自动删除
1
2
3
4upstream bakend {
server 192.168.1.10;
server 192.168.1.11;
}weight
1
2
3
4upstream bakend {
server 192.168.1.10 weight=1;
server 192.168.1.11 weight=2;
}ip_hash 每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session不能跨服务器的问题。
如果后端服务器down掉,要手工down掉1
2
3
4
5
6
upstream resinserver{
ip_hash;
server 192.168.1.10:8080;
server 192.168.1.11:8080;
}fair (插件) 根据相应时间有限分配
1
2
3
4
5upstream resinserver{
server 192.168.1.10:8080;
server 192.168.1.11:8080;
fair;
}
定义错误页面
1 | error_page 500 502 503 504 /50x.html; |
shadowsocks进程检测
- 1 添加cron 任务
1 | crontab -e |
- 2
编辑crontab
1 | * * * * * /bin/sh /root/wp/ssscript.sh |
- 3 编辑ssscript.sh 并且 chmod 775 ./ssscript.sh
1 | #!/bin/sh |
- python 调用系统命令
1 | #!/bin/python |
nginx 配置ssl
1 |
|
nginx websocket configuration
1 | http { |
nginx 日志记录自定义请求头
Client send to server a custom header. Sample, send a device_id header to server. In nginx, we capture this header and write to access_log for debug, monitor, route request. We need to config nginx that:
Enable underscores directive in http selection.
1 | underscores_in_headers on; |
Set header to a variable (if header is customheader, variable is http + custom_header
1 | proxy_set_header device_id $http_device_id; |
Re-config log format in nginx config
1 | log_format main '"device_id:$http_device_id"' |
Send a request with custom header
1 | curl -X POST -H 'device_id:57cfd83ee4b094690a1db5d6' https://localhost.local/api/log/write |