看在nginx使用之前
来源:互联网 发布:easyrecovery for mac 编辑:程序博客网 时间:2024/04/28 08:35
1.启动方式
To start nginx, run the executable file. Once nginx is started, it can be controlled by invoking the executable with the -s parameter. Use the following syntax:
nginx -s signal
Where signal may be one of the following:
stop — fast shutdown
quit — graceful shutdown
reload — reloading the configuration file
reopen — reopening the log files
Serving Static Content
An important web server task is serving out files (such as images or static HTML pages). You will implement an example where, depending on the request, files will be served from different local directories: /data/www (which may contain HTML files) and /data/images (containing images). This will require editing of the configuration file and setting up of a server block inside the http block with two location blocks.
First, create the /data/www directory and put an index.html file with any text content into it and create the /data/images directory and place some images in it.
2.选择location匹配的策略
When nginx selects a location block to serve a request it first checks location directives that specify prefixes, remembering location with thelongest prefix, and then checks regular expressions.If there is a match with a regular expression, nginx picks this location or, otherwise, it picks the one remembered earlier.
server {
location / {
proxy_pass http://localhost:8080/;
}
location ~ \.(gif|jpg|png)$ {
root /data/images;
}
}
3.默认模块
4.如何选择底层connection驱动方式
5.debug方式
http {
server {
error_log /path/to/log debug;
...
error_log memory:32m debug;
6.nginx选择server的方式
6.1 基于host选择server
In this configuration nginx tests only the request’s header field “Host” to determine which server the request should be routed to. If its value does not match any server name, or the request does not contain this header field at all, then nginx will route the request to the default server for this port. In the configuration above,the default server is the first one — which is nginx’s standard default behaviour. It can also be set explicitly which server should be default, with the default_server parameter in the listen directive:server {
listen 80 default_server;
server_name example.net www.example.net;
...
}
6.2 选择server的顺序
- exact name
- longest wildcard name starting with an asterisk, e.g. “*.example.org”
- longest wildcard name ending with an asterisk, e.g. “mail.*”
- first matching regular expression (in order of appearance in a configuration file)
6.3 server的写法
Wildcard names
A wildcard name may contain an asterisk only on the name’s start or end, and only on a dot border. The names “www.*.example.org” and “w*.example.org” are invalid.Miscellaneous names
There are some server names that are treated specially.If it is required to process requests without the “Host” header field in a server block which is not the default, an empty name should be specified:
server {
listen 80;
server_name example.org www.example.org "";
...
}
catch-all
In catch-all server examples the strange name “_” can be seen:server {
listen 80 default_server;
server_name _;
return 444;
}
6.4 针对server_name 过长的两个参数
you should increase server_names_hash_bucket_size: 32
could not build the server_names_hash,
you should increase either server_names_hash_max_size: 512
7.负载均衡
http {
upstream myapp1 {
()| least_conn | ip_hash
server srv1.example.com;
server srv2.example.com;
server srv3.example.com;
}
server {
listen 80;
location / {
proxy_pass http://myapp1;
}
}
}
负载的更多配置http://nginx.org/en/docs/http/ngx_http_upstream_module.html#server
- 看在nginx使用之前
- 在看,之前,起码要
- Nginx在linux上安装之前的准备工作
- 在移动数据库文件之前使用sp_detach_db / sp_attach_db
- 对象在使用之前的初始化
- "Nginx服务器在使用HTML5
- 回看之前的自己
- nginx在centos中安装之前需要进行准备的环境
- 写在分析Nginx源码之前
- 在使用 ItemsSource 之前,项集合必须为空
- 在使用 ItemsSource 之前,项集合必须为空。
- 关于使用RequestWindowFeature为啥一定要在setContentView之前调用
- 对象的初始化:确保对象在使用之前被初始化 `
- MySQLDump在使用之前一定要想到的事情
- MySQLDump在使用之前一定要想到的事情
- 解决getElementsByClassName在IE8之前无法使用的问题
- 如何在viewDidAppear之前使用view的frame正确布局
- 从运行原理及使用场景看Apache和Nginx
- c# sealed 使用方法
- WebSocket协议
- Android Multimedia框架总结(七)C++中MediaPlayer的C/S架构补充及MediaService介绍
- 第二周项目2-程序的多文件组织
- Java知识小结之Serializable
- 看在nginx使用之前
- C#+ArcGIS Engine 空间查询
- Fragment的setUserVisibleHint方法实现视频音频播放暂停
- PL/SQL登陆不成功!出现no logging
- NEFU OJ10 密码
- HDU 1003 Max sum(dp)
- Android播放Assets内音频文件
- 通知公告数据表
- 皮尔森系数